• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Merging problem - id is generated instead of cusotm id.

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I want to update row with some id, but the result is createing a new row.
So I have entity:



Then I do so(see that the ids is the same):



Result: two rows with not my id:
ID | VALUE
---------------------------
1 | value=123456789
2 | value=987654321


So, is it possible in Hibernate to update row in such way ?
Thanks.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just kicking at the can here.

Hibernate sees two detached objects here. Since it didn't load either of them, it doesn't know if they have real representations in the database. When it goes to merge them, it sees that both do not have database representations, and it then creates the db representation, and it creates new ids for both, since each new record is told to use an id from the sequence.

Can you load the one record first, and then merge the new one and see what happens?



Just an idea. I'm speaking purely out of ignorance on this one.

-Cameron
 
Dmitriy Kastikovich
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cameron Wallace McKenzie wrote:

Can you load the one record first, and then merge the new one and see what happens?



Just an idea. I'm speaking purely out of ignorance on this one.



No, I cant load first. I need a hand-set ID on already created entities with id-generators.
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you can load first!

I'm suggesting this not as a final solution, but to see what happens when you initially load an object, and then do a merge. That way you don't have transient objects, but instead, are merging a transient object with a persistent objects.

Doing this as a test case might help you solve your problem, and discover what is going wrong. Then you can adopt your final solution as fit.

It's just an idea. I'd be curious as to why you can't do a test that loads one entity first?

-Cameron McKenzie
reply
    Bookmark Topic Watch Topic
  • New Topic