-->
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.  [ 2 posts ] 
Author Message
 Post subject: Manually set the id for a new object which has sequence gen
PostPosted: Mon May 25, 2009 4:04 pm 
Beginner
Beginner

Joined: Tue Mar 13, 2007 8:26 am
Posts: 25
Hello,

I'm writing some integration test and on the BootStrap of the the tests I'd like to insert all the data that I'll use in the test. So far so good, it's almost working.

The problem is that my classes are mapped with
Code:
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SequenceCliFor")

and apparently I can't set the id for this kind of strategy. Is it true?

Only in the test I must do this something like this:
Code:
DomainClass dc = new DomainClass();
dc.setId(2);
// save dc object (insert it in the database)


If I use merge to save the object the id is changed to the next value in SequenceCliFor, and if I use saveOrUpdate I get a
Quote:
StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1


IMO I should be able to set the id and hibernate should use the id that I setted, and if I don't set any it uses the sequence. Is it possible?

_________________
---
Felipe Marin Cypriano


Top
 Profile  
 
 Post subject: Re: Manually set the id for a new object which has sequence gen
PostPosted: Mon May 25, 2009 6:20 pm 
Newbie

Joined: Mon May 25, 2009 2:03 pm
Posts: 2
When you use a generator strategy hibernate will always assume that object which have an identifier are already persisted on database, so it'll try to update it. The update statement will return 0 rows, as the object row isn't present at the database, this will cause an StaleState exception


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