| Author |
Merging problem - id is generated instead of cusotm id.
|
Dmitriy Kastikovich
Greenhorn
Joined: Jun 29, 2008
Posts: 22
|
|
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.
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
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
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
Dmitriy Kastikovich
Greenhorn
Joined: Jun 29, 2008
Posts: 22
|
|
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
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
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
|
 |
 |
|
|
subject: Merging problem - id is generated instead of cusotm id.
|
|
|