DEV Community

Sonia-dev
Sonia-dev

Posted on

Bean can not resolve jpa /hibernate

Bean can not resolve jpa /hibernate

-1

enter image description hereI'm trying to do a blog - spring boot application using the Hibernate JPA implementation. My problem is that I can't use the mapping , You can see the error message I get in the two pictures below.enter image description here

Top comments (4)

Collapse
 
dineshftu profile image
dineshftu

Please let me see your post entity and person entity classes to see whether i can resolve this for you.

Collapse
 
soniadev profile image
Sonia-dev

package com.example.demo.model;

import javax.persistence.*;
import javax.persistence.OneToMany;
import java.util.Collection;
import java.util.Date;
import java.util.List;

@Entity
public class Post {
public long getId() {
return id;
}

public void setId(long id) {
    this.id = id;
}

public void setTitle(String title) {
    this.title = title;
}

public void setBody(String body) {
    this.body = body;
}

public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
}

public String getTitle() {
    return title;
}

public String getBody() {
    return body;
}

public Date getCreatedDate() {
    return createdDate;
}

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String title;
private String body;
private Date createdDate;

public List<Comment> getComments() {
    return comments;
}

public void setComments(List<Comment> comments) {
    this.comments = comments;
}
@OneToMany(mappedBy = "post", cascade = CascadeType.REMOVE)
private List<Comment>comments;
Enter fullscreen mode Exit fullscreen mode

}

Collapse
 
soniadev profile image
Sonia-dev

package com.example.demo.model;

import javax.persistence.*;
import java.util.Collection;
@Table
@Entity
public class Person {
@id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String username;
public String getEmail() {
return email;
}

public void setEmail(String email) {
    this.email = email;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

private String email;
private String password;
public Person() {
}

public Person(String name) {
    this.username = name;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getName() {
    return username;
}

public void setName(String name) {
    this.username = name;
}
Enter fullscreen mode Exit fullscreen mode

}

Collapse
 
dineshftu profile image
dineshftu

I have gone through the classes which I asked, and I think the issue is the referenceColumn attribute. In your post and person entities you dont have any column name as post_id and person_id. You only have id column in both. So you should be adding id instead of post_id and person_id to the referenceColumn in Comment class. Because jpa is looking for the exact column name in other entities. I think this will work.