• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in Mapping Composite Primary Key with Hibernate

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,
I'm facing difficulty in mapping a composite key to my domain model, where one key is "assigned" (i-e assigned from the application code) and the other I want to designate as "increment" (the DB should auto assign).

For example, Pls. consider the following code snippet:


I've tried embedding the <generator class="increment"> tag inside the <key-property> tag, but, unfortunately it's not supported by Hibernate.

Any help shall be highly appreciated.

Regards,
Reema
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See here.
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Alejandro Perez
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the same problem, and the link you provide is not working, please where I can get the information.

pd: sorry for my english, I'm cuban.
 
subodh joshi
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you plese answer this question i am getting same issue which alredy defined ?and the Link which you posted have no any information
thanksStock market
 
Christian Dillinger
Ranch Hand
Posts: 200
 
subodh joshi
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christine for your reply So from the link you provide what i undersatnd we can not use <generator class="increment" /> in the composite key .Is am i right? If yes do you know how can i overcome this issue.
Thanks in advance
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Taken from chapter 8.4, current Hibernate Reference Doc:
"You cannot use an IdentifierGenerator to generate composite keys. Instead the application must assign its own identifiers."

If the schema definition of <composite-id> does not accept a <generator>-element, there is no way to archive this.
 
subodh joshi
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Christian Dillinger for your quick reply.
i m very thankful of you...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic