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: Loading an object with composite-id
PostPosted: Thu Feb 28, 2008 5:00 am 
Beginner
Beginner

Joined: Tue May 29, 2007 3:14 am
Posts: 28
How can I load an object with a composite-id?
Normally I do it in this way:

Session.Get(obj.GetType, obj.ID)

My example class:

<class name="Translation.Translation, Translation" table="translation" dynamic-insert="false" dynamic-update ="false" batch-size ="10">
<composite-id>
<key-property name="ID" column="id"/>
<key-many-to-one name="Language" column="ID_RefLanguage" class="Translation.Language, Translation"/>
</composite-id>
<property name="TextTrans" column="Text" type="String" length="50" />
<many-to-one name="TranslationType" column="ID_RefTranslationType" class="Translation.TranslationType, Translation" fetch="join"/>
</class>





[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 28, 2008 5:11 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
From the documentation:

Quote:
Unfortunately, this approach to composite identifiers means that a persistent object is its own identifier. There is no convenient "handle" other than the object itself. You must instantiate an instance of the persistent class itself and populate its identifier properties before you can load() the persistent state associated with a composite key.

We will describe a much more convenient approach where the composite identifier is implemented as a seperate class in Section 7.4, “Components as composite identifiers”. The attributes described below apply only to this alternative approach:

*

name (optional, required for this approach): A property of component type that holds the composite identifier (see next section).
*

access (optional - defaults to property): The strategy NHibernate should use for accessing the property value.
*

class (optional - defaults to the property type determined by reflection): The component class used as a composite identifier (see next section).


For more details see:

http://www.hibernate.org/hib_docs/nhibe ... ompositeid

Cheers,

Symon.

_________________
Symon Rottem
http://blog.symbiotic-development.com


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.