Hi everybody,
I've got some issues converting my code to do some automatic processing using an Interceptor. Let's say I'v got a class A with a persistent set called "children", containing objects of class B. When an object of class A is saved or updated I have to add some instances of B to the "children" set.
I thought I could use the onFlushDirty method and add objects to children:
public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types
) throws CallbackException {
B b = new B();
b.setKey("dummyKey");
b.setProperty1("dummy1");
b.setProperty2("dummy2");
((A)entity).getChildren().add(b);
}
This code doesn't work. I tried also this, with no success:
public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types
) throws CallbackException {
B b = new B();
b.setKey("dummyKey");
b.setProperty1("dummy1");
b.setProperty2("dummy2");
Set set = new HashSet(((A)entity).getChildren());
set.add(b);
((A)entity).setChildren(set);
}
Should I play with the currentState array values? Or the issue is in WHEN the flushDirty method is invoked?
Any help appreciated.
Regards,
lorenzo
|