Hibernate version:
3
--
Hi.
I'm seeking some examples and documentation on the new Event System, particulary the Save/Delete and flush events.
By first sight it looks like it's a big reorganization of Interceptor interface. But the interceptor has several limitations like:
- I can't use the session. I have to clone it with the same connection.
- The parameters are a mess:
onFlushDirty method is:
Code:
public boolean onFlushDirty(
Object entity,
Serializable id,
Object[] currentState,
Object[] previousState,
String[] propertyNames,
Type[] types)
1 - I have the entity that has the properties.
2 - I have the Id (I can get it in the entity);
3- I have current state, that I can get in the object. And it's an array (!?). I feel like I'm programming assembler here.
4- This is new information, but again in an array! why not an instance of the entity?
5- propertyName: I hate to search a name in an array to them get the value back in another list. It's a pain.
6- Types: This is tricky, but may be usefull.
Looks like the Event just put all this in a Event Object (like FlushEntityEvent).
Code:
public void onFlushEntity(FlushEntityEvent event)
...
flushentityevent wrapper. What does each method do ? where is the documentation of those classes??
Code:
Method Summary
Object[] getDatabaseSnapshot()
int[] getDirtyProperties()
Object getEntity()
EntityEntry getEntityEntry()
Object[] getPropertyValues()
boolean hasDatabaseSnapshot()
boolean hasDirtyCollection()
boolean isDirtyCheckHandledByInterceptor()
boolean isDirtyCheckPossible()
void setDatabaseSnapshot(Object[] databaseSnapshot)
void setDirtyCheckHandledByInterceptor(boolean dirtyCheckHandledByInterceptor)
void setDirtyCheckPossible(boolean dirtyCheckPossible)
void setDirtyProperties(int[] dirtyProperties)
void setHasDirtyCollection(boolean hasDirtyCollection)
void setPropertyValues(Object[] propertyValues)
But what happens if I change a property of the entity during onFlushEntity execution of DefaultFlushEntityEventListener event implementation instead of changing it in the array of properties given by getPropertyMethods?
Because as I said on the Interceptor above, I think that it's really boring to change values in an array of objects when I have a powerfull Object To Relational Mapping tool.
And what If I want to query database? how do I do this? I still need to clone the session? but where is the session?
damn, I really want to belive that the Event System is better than this. But I can't find any information on how it works!
There is only one page of documentation on the reference guide in this subject :([/b]