This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes JPA @ManyToOne Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA @ManyToOne" Watch "JPA @ManyToOne" New topic

JPA @ManyToOne

Jean-Fran´┐Żois Liesenborghs

Joined: Jul 16, 2008
Posts: 1
Hi evryone,

I have two entity SupportingDocument n <====> 1 SupportingDocumentType

public class SupportingDocument{

private Long id;
private String registeryKey;
private Date date;
private String stateCd;
private String comment;
@JoinColumn(name = "DOC_TYPE_CD", nullable = false, referencedColumnName="TYPE_CD")
private SupportingDocumentType supportingDocumentType;

public class SupportingDocumentType {

private Long id;
private String typeCd;
private String description;
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_

Did you know where I'm wrong ?

Abraham Gimeno

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
I agree. Here's the link:
subject: JPA @ManyToOne