-->
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.  [ 7 posts ] 
Author Message
 Post subject: Composite id's properties
PostPosted: Tue Mar 14, 2006 10:04 am 
Newbie

Joined: Tue Feb 22, 2005 3:26 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Can any body tell me how to get the properties of the composite id from the Configuration instance?
<class
name="vpo.Tcustcontactorrela"
table="TCUSTCONTACTORRELA"
>
<composite-id name="id" class="vpo.TcustomercontactorPK">
<key-property name="ccustno" column="C_CUSTNO"></key-property>
<key-property name="lcontactorid" column="L_CONTACTORID"></key-property>
<key-property name="ccontactortypecode" column="C_CONTACTORTYPECODE"></key-property>
</composite-id>
</class>
I know how to get the identifier: cfg.getClassMapping(entity.getClass()).getIdentifier(); But what about the composite id?
Thank you advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 10:26 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Won't that be the composite id? You should be able to use this to check if a particular id is composite or not:
Code:
cfg.getClassMapping(entity.getClass()).getIdentifier().isSimpleValue();
Also, one of these should be true for composite ids (depending on whether or not the compsite-id is mapped, i.e. whether or not it has the class="???" attribute):
Code:
cfg.getClassMapping(entity.getClass()).getIdentifier().getType().isComponentType();
cfg.getClassMapping(entity.getClass()).getIdentifier().getType().isEntityType();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 8:56 am 
Newbie

Joined: Tue Feb 22, 2005 3:26 am
Posts: 8
Thank you tenwit, assume that the composite id is mapped, but now I still don't know how to retrieve the property's name.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 5:22 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
For that sort of detail, you want getIdentifierMapper() instead of getIdentifier(). Then you can use getPropertyIterator() and getComponentClass() to go through the hibernate properties and POJO accessors.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 7:24 pm 
Newbie

Joined: Tue Feb 22, 2005 3:26 am
Posts: 8
I'm very sorry to forget to tell the version of hibernate I'm using.
The version I'm using now is 2.1.2 final, so there is no such method in the PersistentClass. Is that mean I can't get the properties' name of the composite id in hibernate 2.1.2?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 9:12 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't say for sure, but I think what you need is
Code:
((Component) cfg.getClassMapping(entity.getClass()).getIdentifier()).getPropertyIterator()
Of course, you need to do the appropriate instanceof checks, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 8:16 am 
Newbie

Joined: Tue Feb 22, 2005 3:26 am
Posts: 8
Hi, tenwit, with your help, I have solved my problems.
I'm very glad to say thank you and you are so kind a person, : )


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