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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate composite key problem
PostPosted: Mon Oct 13, 2008 9:09 am 
Newbie

Joined: Mon Oct 13, 2008 8:35 am
Posts: 1
Hi everyone,

I hope someone is able to help me in the right direction. I am trying to do all the mapping on our database, which unfortunately i am not able to modify. The problem is between two tables using composite keys.

I have the following two tables:

AppNo:
Code:
AppNo (PK)
Country (PK)
Description
Etc...


AppNo_prices:
Code:
AppNo (PK)
Country (PK)
Price


Which is linked using the AppNo & Country as composite primiary keys.

Is this possible to do at all? Does anyone have any examples of this?

I have looked at the following examples:
http://java-aap.blogspot.com/2006/04/hibernate-annotations-composite.html
http://boris.kirzner.info/blog/archives/2008/07/19/hibernate-annotations-the-many-to-many-association-with-composite-key/

I have tried to use the @Embeddable in the same way, but they do not really do what i need.

Hibernate version:
Hibernate 3.2.1
Hibernate Annotations 3.4.0 GA

Thanks for all your help


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 26, 2008 4:19 pm 
Newbie

Joined: Sun Oct 26, 2008 4:00 pm
Posts: 1
Hello champ1

As far as I can understand from your sample, you're not dealing with Many-To-Many association, but with One-To-Many one.

Thus, my example is not exactly what you need, but you should make the things in the same spirit:
  • Create a class (PK) for composite primary key and mark it with @Embeddable.
  • Add a field of type PK to your class(es) and mark it with @EmbeddedId.
  • Make sure you create and update the key either directly or using transient properties when this is required.

Hope this helps

_________________
Boris Kirzner
http://boris.kirzner.info/blog


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.