With an interceptor I'm trying to set a property of a persistent class, just before it's save or updated. Unfortu-nately the property I'm setting in the interceptor isn't written to the DB.
My Code looks as following:
Code:
public boolean onFlushDirty(Object entity, Serializable id, Object[] state,
Object[] arg3, String[] arg4, Type[] arg5) throws CallbackException {
if (entity instanceof ClassB) {
CapiPK pk = (CapiPK)id;
ClassB b = (ClassB)entity;
b.setApid(pk.getPid());
return true;
}
return false;
}
public boolean onSave(Object entity, Serializable id, Object[] state,
String[] propertyNames, Type[] types) throws CallbackException {
if (entity instanceof ClassB) {
CapiPK pk = (CapiPK)id;
ClassB b = (ClassB)entity;
b.setApid(pk.getPid());
return true;
}
return false;
}
As you can see I want to set the property Apid of the ClassB every time a ClassB gets saved or updated. By debugging the interceptor, I can see, that the code inside onSave/onFlushDirty works fine, but the Apid Column is never written to the DB.
I tried to achieve the same with the Livecycle interface. This does exactly what I want to have, but I don't like the idea of implementing Lifecycle in all my persistent classes very much.
Any ideas about what could be wrong or how to solve this kind of problems in an other nice way (without implementing Lifecycle) would be appreciated.
BTW:
Hibernate Version is 2.1.4
DB is MySQL 4.0.20a
Best Regards
Ernst