-->
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.  [ 3 posts ] 
Author Message
 Post subject: Composite Id Mapping in Hibernate Annotation
PostPosted: Mon Mar 24, 2008 9:01 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
In .hbm file ,we can define composite primary key on the class properties.
for exam-

Class Person{

private String firstName;

private String lastName;

------------------
---------------------
---------------------
-------------------
}

has a composite primary key (firstName,lastName).We can map this composite key in .hbm file like this.

<composite-id>
<key-property name="firstName"/>
<key-property name="lastName"/>
</composite-id>



Is there any way in Hibernate annotation to map composite primary key on properties of same class. (without creating a new @Embeddable class, which will use as primary key).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 6:26 am 
Newbie

Joined: Mon Apr 21, 2008 7:11 am
Posts: 4
Location: Sevilla, Spain
i'm interested too


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 28, 2008 12:49 pm 
Newbie

Joined: Mon Apr 28, 2008 12:44 pm
Posts: 1
http://www.hibernate.org/hib_docs/annot ... ntity.html


You can define a composite primary key through several syntaxes:

annotate the component property as @Id and make the component class @Embeddable
annotate the component property as @EmbeddedId
annotate the class as @IdClass and annotate each property of the entity involved in the primary key with @Id




Hope this helps !!


- Vinant


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