I noticed strange behaviour on our system when using HibernateTemplate in Spring - compared to doing same thing with just Hibernate session.
We have a node-table where child-parent relationship is described and each node has parent_id. Table has also an index column that we would like to have a not null constraint. This works ok in simple testcase when using just hibernate session, however when we use HibernateTemplate I noticed that hibernate behaves differently:
1) insert into nodes (title, state, parent_id, owner_group_id, id) values (?, ?, ?, ?, ?)
2) Hibernate: update nodes set parent_id=null, position=null where parent_id=? and position=?
3) Hibernate: update nodes set parent_id=?, position=? where id=?
Step two causes constraint violation, since there is an update to null values.
Package with everything except the database to test:
My post to hibernate forum:
Any ideas or thoughts would be helpfull.
I will try next to set constraint deferred - so that the transaction will be handled 'till the end before the constraints are checked.