Hello,
I need to implement a class where the instance need to embed the creation date and the last modification date.
Regarding the documentation, the Lifecycle implementation seems to be exactly what i need. So imagine the following class:
Code:
public class Foo implements Lifecycle
{
/**
* The Class Log.
*/
private static Log log = LogFactory.getLog(Foo.class);
...
public boolean onSave(Session arg0) throws CallbackException
{
log.debug("onSave()");
return NO_VETO;
}
public boolean onUpdate(Session arg0) throws CallbackException
{
log.debug("onUpdate()");
return NO_VETO;
}
public boolean onDelete(Session arg0) throws CallbackException
{
log.debug("onDelete()");
return NO_VETO;
}
public void onLoad(Session arg0, Serializable arg1)
{
log.debug("onLoad()");
}
...
}
Now I have the following code:
Code:
Transaction tx = session.currentTransaction();
Foo foo = // ... creating or retrieving the object, depending of the context.
session.save(foo); // To have the same code for modification or creation
tx.commit();
When the object is created, there is no problem, the method onSave() is called, but when modified, the nor onSave() nor onUpdate() (that is normal) are called.
Does anybody have a possible explanation - I use Hibernate 2.0.3?