請告訴我爲什麼我錯誤地鏈接了這些表格。 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop INFO:HHH000030:清理連接池[jdbc:oracle:thin:@ ARS-PS-DEV:1521:ars] 線程「main」 java.lang.ExceptionInInitializerError:Initial SessionFactory failedorg.hibernate.AnnotationException:mappedBy引用未知目標實體屬性:com.ecls.ARSTools.DAO.Certificate.certificateFields中的com.ecls.ARSTools.DAO.CertificateField.сertificate at com.ecls .ARSTools.Tools.HibernateSessionFactory.buildSessionFactory(HibernateSessionFactory.java:21) at com.ecls.ARSTools.Tools.HibernateSessionFactory。(HibernateSessionFactory.java:10) at com.ecls.ARSTools.Tools.ImplARS。(ImplARS.java :14) at ecls.temp.AppMain.main(AppMain.java:16)Hibernate mappedBy
@Entity
@Table(name= "CERTIFICATE")
public class Certificate implements IAvailableID{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cert_generator")
@SequenceGenerator(name="cert_generator", sequenceName = "SWS_CERTIFICATE_ID", allocationSize=1)
@Column(name = "ID")
private Long id;
@Column(name= "NAME", unique = true, nullable = false, length=50)
private String name;
@OneToMany(targetEntity=CertificateField.class, mappedBy = "сertificate", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<CertificateField> certificateFields=new ArrayList<CertificateField>();
public Certificate() {
super();
}
public Certificate(String name, List<CertificateField> certificateFields) {
super();
this.name = name;
this.certificateFields = certificateFields;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<CertificateField> getCertificateFields() {
return certificateFields;
}
public void setCertificateFields(List<CertificateField> certificateFields) {
this.certificateFields = certificateFields;
}
@Override
public String toString() {
String res;
res="-------------------\n";
res+="Certificate [id=" + id + ", name=" + name+"]\n";
for(CertificateField item:certificateFields){
res+=item.toString()+"\n";
}
return res;
}
}
@Entity
@Table(name= "CERTIFICATE_FIELD")
public class CertificateField implements IAvailableID{
@Id
@Column(name= "ID")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name= "NAME", nullable = false, length=50)
private String name;
@Column(name= "VALUE", nullable = false, length=50)
private String value;
@ManyToOne(targetEntity=Certificate.class, cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinColumn(name = "CERTIFICATE_ID", referencedColumnName="ID", nullable = false)
private Certificate certificate;
public CertificateField(){
super();
}
public CertificateField(String name, String value, Certificate certificate) {
super();
this.name = name;
this.value = value;
this.certificate = certificate;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Certificate getCertificate() {
return certificate;
}
public void setCertificate(Certificate certificate) {
this.certificate = certificate;
}
@Override
public String toString() {
return "certificate field [id=" + getId() + ", name=" + getName()+ ", value=" + getValue()+"]";
}
}
嘗試沒有「targetEntity」屬性?因爲任何像樣的JPA提供者都應該能夠通過泛型獲取相關類型 –
結果是一樣的。我已經嘗試過這個(( –
在'persistence.xml'? –