| Author |
JPA @ManyToOne
|
Jean-Fran�ois Liesenborghs
Greenhorn
Joined: Jul 16, 2008
Posts: 1
|
|
Hi evryone, I have two entity SupportingDocument n <====> 1 SupportingDocumentType @Entity @Table(name="T_COR_SUP_DOC") public class SupportingDocument{ @Id @Column(name="ID") @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(name="REGISTERY_KEY") private String registeryKey; @Column(name="SUP_DATE") private Date date; @Column(name="STATE_CD") private String stateCd; @Column(name="SUP_COMMENT") private String comment; @ManyToOne @JoinColumn(name = "DOC_TYPE_CD", nullable = false, referencedColumnName="TYPE_CD") private SupportingDocumentType supportingDocumentType; @Entity @Table(name="T_COR_SUP_DOC_TYPE") public class SupportingDocumentType { @Id @Column(name="ID") @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @Column(name="TYPE_CD") private String typeCd; @Column(name="DESCRIPTION") private String description; @OneToMany(mappedBy="supportingDocumentType") private List<SupportingDocument> supportingDocuments; I have a this message when I try to get the SupportingDocuments from DB: Hibernate: select supporting0_.ID as ID11_, supporting0_.DESCRIPTION as DESCRIPT 2_11_, supporting0_.TYPE_CD as TYPE3_11_ from T_COR_SUP_DOC_TYPE supporting0_ java.lang.ClassCastException: eu.europa.ec.agri.agrex.core.domain.SupportingDocumentType Did you know where I'm wrong ? Thanks, JF
|
 |
Abraham Gimeno
Greenhorn
Joined: Jul 16, 2008
Posts: 7
|
|
|
The anotation referencedColumnName I think should reference a column that or it's a primary key (single or composite) or a primary key candidate, that's a unique column. Your column TYPE_CD in SupportingDocumentType I believe must contain nullable = false, unique = true
|
 |
 |
|
|
subject: JPA @ManyToOne
|
|
|