Wow! What a surprise for me! I was unaware of this.
Now, I wonder if there is any way Hibernate says automatically Oracle to insert into the dabase the current date (something like SYSDATE)...
I ask that because I have a setCreated() and getCreated() methods that have to insert and retrieve a object creation date. What I have now in my database is a Date field with a SYSDATE as default value. So when I create an object a leave the creation date field empty(null) so that the database do this task for me. This force me to make a Session.refresh() after inserting the a object when I need to access the creation date.
For example, if I insert a User object:
Code:
...
User user = new User();
user.setName( "Musicolo" );
....
session.save( user );
session.flush(); // Don't know why I have to do that manually
session.connection().commit() // Don't know have to do that manually
System.out.println( user.getCreated() ); // This prints: null
session.refresh( user );
System.out.prinln( user.getCreated() );// This prints: 01/03/2005 12:37:12.0
I konw I should use Transaction approach, but I don't know how to get that. Apart from this comment, do you know how to achived what I said at the begging?
Many thanks to all!
PS. If you are thinking about using System.currentmillis() to insert the Date, forget it, as this approach is not valid because this project is running in distributed environment and there is no gurantee all machines have the very same time.