-->
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.  [ 4 posts ] 
Author Message
 Post subject: <composite-id> without class id
PostPosted: Wed May 10, 2006 5:21 am 
Newbie

Joined: Wed May 10, 2006 5:09 am
Posts: 4
Hi,

I found in "Hibernate in Action" the following example (page 333):
<composite-id>
<key-property name="username" column="USERNAME"/>
<key-property name="organizationId" column="ORGANIZATION_ID"/>
</composite-id>

The problem is that I can't find a way to fetch this composite-id in java.
ClassMetadata.getIdentifierPropertyName() returns null and ClassMetadata.getIdentifier() returns the all class.

Is there any other way?

Thanks
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 8:49 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
replace your composite-id element with the below information

Quote:
<composite-id name="myCompId" class="MyCompositePK">
<key-property name="username" column="USERNAME"/>
<key-property name="organizationId" column="ORGANIZATION_ID"/>
</composite-id>

public class MyCompositePK implements Serializable {
private String username;
private String organizationId;
}

public MyPersistClass {
private MyCompositePK myCompId;
....
}


Then you can get identifier information from SessionFactory.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 4:51 am 
Newbie

Joined: Wed May 10, 2006 5:09 am
Posts: 4
Ok,
But the question if I can get the ClassMetadata.getIdentifier() without the
class="MyCompositePK"

Thanks,
Alex


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 11, 2006 5:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If you use integrated composite key then you need to populate each field that makes up the key, in the domain object, to do an operation that requires the key, eg, load and get. There is no Java key to return as its just properties on the domain object.


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