-->
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: Composite string fields as a ID in hbm.xml?
PostPosted: Tue Nov 15, 2005 3:11 am 
Newbie

Joined: Fri Nov 04, 2005 2:49 am
Posts: 6
Hibernate version: 3

<class name="UserProfile" table="user_profile">
<id name="userid" column="userid" type="java.lang.Short">
<generator class="native"/>
</id>


In the original design, the data structure does not have a id field.
In order to compromize with Hibernate, a userid field is introduced.
It works fine with Struts.

I wonder if I can have a composite fields which composes of two string fields. If I can, how can I define it in ???.hbm.xml?

Thanks


Top
 Profile  
 
 Post subject: it is very simple for hibernate
PostPosted: Tue Nov 15, 2005 3:33 am 
Newbie

Joined: Thu Jun 23, 2005 9:23 pm
Posts: 13
it is very simple for hibernate . There is a solution about the composit-id
you can read the document about hibernate composite-id.
i reference a bit from the hibernate document :

Quote:
For a table with a composite key, you may map multiple properties of the class as identifier properties. The
<composite-id> element accepts <key-property> property mappings and <key-many-to-one> mappings as
child elements.
<composite-id>
<key-property name="medicareNumber"/>
<key-property name="dependent"/>
</composite-id>
Your persistent class must override equals() and hashCode() to implement composite identifier equality. It
must also implements Serializable.


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.