Answer the question
In order to leave comments, you need to log in
Hibernate ManyToOne how to determine the type?
Hello.
I have two tables, I'm trying to relate them with a one-to-many relationship ─Category @OneToMany Content
@Entity
@Table(name = "categorys")
public class Category {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "is_active", columnDefinition = "boolean default true")
private boolean isActive;
@Column(name = "title")
private String title;
@Column(name = "subtitle")
private String subtitle;
private List<Content> contents;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public boolean isActive() {
return isActive;
}
public void setActive(boolean isActive) {
this.isActive = isActive;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getSubtitle() {
return subtitle;
}
public void setSubtitle(String subtitle) {
this.subtitle = subtitle;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "category")
public List<Content> getContents() {
return contents;
}
public void setContents(List<Content> contents) {
this.contents = contents;
}
}
@Entity
@Table(name = "contents")
public class Content {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id")
private Long id;
@Column(name = "content")
private String content;
private Category category;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@ManyToOne( fetch = FetchType.LAZY)
@JoinColumn(name = "category_id", nullable = false)
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
}
org.hibernate.MappingException: Could not determine type for: net.codejava.spring.model.Category, at table: contents, for columns: [org.hibernate.mapping.Column(category)]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question