This is in Hibernate 2.1.7.
I have a simple class Customergroups (with a hilo indentifier).
When I simply instantiate a new object and save it, like this:
Code:
Customergroup object = new Customergroup();
sess.saveOrUpdate(object);
sess.flush();
sess.connection().commit();
this is the generated SQL which creates the entire record in one query
Code:
Hibernate: insert into customergroups (customergroupname, customergroupid) values (?, ?)
No problem so far. But for various reasons I need to get an identifier assigned at the start of the use case, so I do this:
Code:
Customergroup object = new Customergroup();
sess.saveOrUpdate(object); //assign id
...do some work...
object.setCustomergroupname("test");
sess.saveOrUpdate(object);
sess.flush();
sess.connection().commit();
This is the generated SQL this time, inserting only the id, then updating it with the name:
Code:
Hibernate: insert into customergroups (customergroupname, customergroupid) values (?, ?)
Hibernate: update customergroups set customergroupname=? where customergroupid=?
This means that I can't have a not-null constraint on the name column in the customergroups table.
How can I get Hibernate to issue a single INSERT query even when I save the object in the session and then update it?
Any hints much appreciated