-->
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.  [ 1 post ] 
Author Message
 Post subject: Saving New Entities with Manually Set Identifiers changes id
PostPosted: Thu Jul 30, 2009 5:14 am 
Newbie

Joined: Wed Jul 29, 2009 6:52 am
Posts: 5
I am trying to save entities whose id getMethod is annotated with:

Code:
   @Id
   @GeneratedValue(strategy=GenerationType.AUTO)


If I use hibernateTemplate.save(...) it persists the object but changes any already set id.
If I use saveOrUpdate I get a stale state exception:

Code:
org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1


I am happy for the system to create id for when the id field (a Long) is null but I want it to leave them alone when they are set - either creating or merging while keeping the existing id. If I was using mapping I would use the annotation unavailable unsaved-value option.

I also have a persisted creationDateTime field annotated with:

Code:
@Temporal (TemporalType.TIMESTAMP)


Might this be creating a side affect? Should I only use this annotation if I want hibernate to use the getter for versioning?

Finally I should mention that the entity I am trying to persist has child entities of the same class and other statically set ids.

Any ideas on how to avoid the exception, allow static ids and still automatic id generation?

Thank you,

Tim Milstead.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.