ho bisogno di fare rapporto OneToMany ma appare questo errore mappedBy riferimento una proprietà un'entità obiettivo sconosciuto questo è genitore Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
causati da: org.hibernate.AnnotationException: mappedBy riferimento una proprietà sconosciuta entità di destinazione
package com.dating.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="question")
public class PsyQuestions {
@Id
@GenericGenerator(name="autoGen" ,strategy="increment")
@GeneratedValue(generator="autoGen")
@Column(name="questionid")
private long psyQuestionId;
@Column(name="questiontext")
private String question;
@OneToMany(fetch = FetchType.LAZY,mappedBy="question")
private List<PsyOptions> productlist=new ArrayList<PsyOptions>();
public PsyQuestions() {
super();
}
public List<PsyOptions> getProductlist() {
return productlist;
}
public void setProductlist(List<PsyOptions> productlist) {
this.productlist = productlist;
}
public long getPsyQuestionId() {
return psyQuestionId;
}
public void setPsyQuestionId(long psyQuestionId) {
this.psyQuestionId = psyQuestionId;
}
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
}
e questa classe bambino
package com.dating.model;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name="option")
public class PsyOptions {
@Id
@GenericGenerator(name="autoGen" ,strategy="increment")
@GeneratedValue(generator="autoGen")
@Column(name="optionid")
private long psyOptionId;
@Column(name="optiontext")
private String optionText;
@JoinColumn(name = "questionid")
@ManyToOne(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
PsyQuestions psyQuestions;
public PsyOptions() {
super();
}
public PsyQuestions getPsyQuestions() {
return psyQuestions;
}
public void setPsyQuestions(PsyQuestions psyQuestions) {
this.psyQuestions = psyQuestions;
}
public long getPsyOptionId() {
return psyOptionId;
}
public void setPsyOptionId(long psyOptionId) {
this.psyOptionId = psyOptionId;
}
public String getOptionText() {
return optionText;
}
public void setOptionText(String optionText) {
this.optionText = optionText;
}
}
attributo mappedBy già impostato per l'entità psyQuestions che mappa sulla tabella delle domande –
@AliAliAbdelFatah il codice che hai pubblicato mostra '@OneToMany (fetch = FetchType.LAZY, mappedBy =" question ")'. Questo deve cambiare come menzionato nella risposta. – melc
grazie mille è risolto il mio errore è mettere il nome della tabella in mappedBy attributo –