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: CompositeID
PostPosted: Tue Dec 19, 2006 8:29 am 
Newbie

Joined: Sun Nov 05, 2006 10:19 am
Posts: 13
I have the next 3 tables

Products
{
Id (PK)
Name
}

Component
{
Id (PK)
Name
}

ProductComp
{
ProductId
ComponentId
Details
Other1
Other2
Other3
}


The idea is that (ProductId & ComponentId) makes a composite primary key...

Can you give me an example of mapping these tables...Is it possible without a specific (dummy) composite class?...just using 3 classes in total

Also it will be niced to see an example using attributes and not xml files...But if it's possible only using xml and 3 mapping classes is ok.

Thx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 4:03 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
First, you should know that composite-id are not recommended. If possible, they must be avoided and only used because of legacy databases.

So, this said
* Absolutely no problem for what you want to do. Hibernate is able to handle the cases where a composite-id is represented by a specific composite class or only field in one object. Still, you will maybe like to know the best practice is to use a class to represent a compositeId. In fact, this makes easier reusability, for example in the case where you'd like to reference the same primary-key from a new other class.

* You will find the example in the reference documentation : http://www.hibernate.org/hib_docs/v3/re ... ompositeid
This doc is very thorough, don't hesitate to refer to it as often as necessary.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.