Thank you again for your comment, but it is still not what I need.
What I have to do is to convert my existing DAO code implemented with TopLink to Hibernate. The problem is because there are some different in their programming model.
In TopLink, there is a method, registerObject() which register a transient with TopLink session. At the time this method is called, it is not required that all required properties of the object has to be set. Its properties can be set after the object is registed and TopLink will just issue a single INSERT statement at transaction commit time.
For example, existing TopLink code will look like this
Code:
// In DAO
public Employee createEmployee(String code) {
Employee e = new Employee();
e.setCode(code);
session.registerObject(e); // TopLink API
return e;
}
// Later in caller code
.. Begin transaction
Employee e = employeeDAO.createEmployee("CODE");
e.setName("NAME");
.. commit transaction
At commit time, only one INSERT statement is generated to insert both code and name property.
If I convert above code to following Hibernate code
Code:
// In DAO
public Employee createEmployee(String code) {
Employee e = new Employee();
e.setCode(code);
session.save(e); // Hibernate API
return e;
}
// Later in caller code
.. Begin transaction
Employee e = employeeDAO.createEmployee("CODE");
e.setName("NAME");
.. commit transaction
This code generated two SQL statement. First one is INSERT caused by Session.save() method which only insert code column. The second statement is UPDATE the name column which is generated by Transaction.commit() method. The first INSERT record will fail because it only set code column while both code and name columns are mandatory.
What I am trying to find is the equivalent to TopLink registerObject method which does not cause the INSERT statement to insert just the properties which are set at the time is method is called, but rather generate INSERT command with all properties set at the time transaction is commit.
But if there is no method in Hibernate with this same behaviour, I will have to change my existing DAO code to populate all mandatory properties before calling Session.save().
Best regards,