-->
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: Changing an object after persisting before flushing
PostPosted: Wed Sep 15, 2010 9:33 am 
Newbie

Joined: Wed Sep 15, 2010 8:53 am
Posts: 1
I create an object which I persist to the session. After persisting the object I change the object using a setter method. When the object is being flushed, the old value is inserted into the database.

After digging in the Hibernate source code I have found the following comment in the class AbstractEntityPersister in the method insert(final Serializable id,
final Object[] fields, final boolean[] notNull, final int j, final String sql, final Object object, final SessionImplementor session) throws HibernateException:

Code:
// Write the values of fields onto the prepared statement - we MUST use the state at the time the
// insert was issued (cos of foreign key constraints). Not necessarily the object's current state


This is the case in Hibernate 3.2.4sp1, 3.3.2 and 3.5.5.

I first persist the entity, because in this particular use case I need to show the identifier (which is generated using a sequence when persisting) on the screen.

Why is this (the comment says cos of foreign key constraints, but what can go wrong)? And how can I accomplish that the new values are stored in the database?


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.