• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how we use composite key in hibernate

 
Ashutosh kumar singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using hibernate 3.0. In which i don't have idea about composite key.how i define composite key and how i define more than one primary key, Means how i define composite key in .hbm file.
if any body have much idea then please share with me.

it's very urgent....
 
Ganesh Gowtham
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i have an idea with respect to annotations
say you domain object is Person which has ssn , name ,..... (Ssn & name forms composite)
you need to create class called PersonPK.java with class level annotation @Embeddable

in normal Person class add another annotation called @IdClass(PersonPK.class) along with @Entity ,@Table
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Gowtham.

As my PETA friends say, there's more than one way to skin a cat.

For composite keys, there are a few annotations that will do the trick:

@Embeddable & @Embeddable
@Id
@IdClass

Each annotation provides a slightly different approach to implementing compound primary keys.

Here's a little tutorial on implementing compound primary keys with Hibernate and JPA.

Creating Compound Primary Keys with Hibernate and JPA Annotations

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic