-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Simple clarification
PostPosted: Tue Jun 22, 2010 3:13 pm 
Newbie

Joined: Tue Jun 22, 2010 2:50 pm
Posts: 2
I have a schema (simplified) as follows, 2 entities with a one to many association between DEALER and BUSINESS_OFFICE (there can be many business offices under a single dealer):

DEALER (
DEALER_ID PK,
NAME
)

BUSINESS_OFFICE (
BUSINESS_OFFICE_ID PK,
DEALER_ID FK to DEALER.DEALER_ID
NAME
)

and domain object fields annotated as follows:

Dealer class:

@Id
@Column(name="DEALER_ID")
private int dealerId;
..other attributes..

@OneToMany
@JoinTable(name = "BUSINESS_OFFICE", joinColumns = {@JoinColumn(name="dealerId", referencedColumnName="DEALER_ID")})
private Set<BusinessOffice> businessOffices = new HashSet<BusinessOffice>(0);

Business office class:

@Id
@Column(name="BUSINESS_OFFICE_ID")
private int businessOfficeId;
.. other attributes ..

The problem I am having is with the OneToMany mapping, I get this error message:

Caused by: org.hibernate.MappingException: Foreign key (FKD13E481B940D703:BUSINESS_OFFICE [businessOffices_BUSINESS_OFFICE_ID])) must have same number of columns as the referenced primary key (BUSINESS_OFFICE [internalDealerId,businessOffices_BUSINESS_OFFICE_ID])

I have no idea what in the world this means... there is only 1 primary key in BUSINESS_OFFICE both as annotated by @Id in the class and in the database table..why is it implying that there is a composite key in BUSINESS_OFFICE? In the BUSINESS_OFFICE table "internalDealerId" is not a PK but rather a FK to the DEALER table.

Any ideas what I am doing wrong? this is a simple association, nothing complex, not sure what I am missing.. thanks much!


Top
 Profile  
 
 Post subject: Re: Simple clarification
PostPosted: Tue Jun 22, 2010 5:45 pm 
Regular
Regular

Joined: Mon Aug 07, 2006 6:22 pm
Posts: 67
I think the basic problem is that you don't need a @JoinTable, just a @JoinColumn.

Also, JoinColumn values are column names, not property names, so '@JoinColumn(name="dealerId", referencedColumnName="DEALER_ID")' should be '@JoinColumn(name="DEALER_ID", referencedColumnName="DEALER_ID")'.


Top
 Profile  
 
 Post subject: Re: Simple clarification
PostPosted: Tue Jun 22, 2010 7:10 pm 
Newbie

Joined: Tue Jun 22, 2010 2:50 pm
Posts: 2
excellent, that worked..

I guess JoinTable is only then you have a separate association table :) thanks for clarifying it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.