views:

29

answers:

1

Hello Overflowers,

I am working with Spring and Hibernate. I have an object which was retrieved from the database with HibernateTemplate.

When I modify this object Hibernate is making inserts into the database before the data is ready to be inserted, the result is a lot of database errors along the line of "cannot insert NULL into ...".

Is there a way to tell Spring/Hibernate "don't update the database with this until I call HibernateTemplate.persist()"? I looked in the HibernateTemplate javadoc but couldn't find anything

+1  A: 

Hibernate is flushing changes because you use transaction scoped persistence context. That means that all managed entities are synchronized with database when the transaction commits. If you don't like it, then simply don't make your method a transactional one. This way entity you get will not be synchronized with database - there wont be any transaction commit.

Paul Szulc
do you need more detailes answer?
Paul Szulc