Hibernate version:
3.05
--
Hi.
Currently an event listener is called to all classes mapped in the configuration of my hibernate application. This makes event system powerful to build audit, replication and that kind of general propose codification.
Well, but to create events to a specific class of objects, or maybe to move business logic commonly used in database triggers to the database independent level, how it will perform? Is it a good idea?
By the programming point of view it would be interesting to have a fine grained event mapping to do this.
Todays implementation would lead to that kind of code:
Code:
public class MyGeneralFlush extends DefaultFlushEntityEventListener {
public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
if (evt.getEntity() instanceof foo) {
// do foo logic
} else if (evt.getEntity() instanceof foo2) {
// do foo2 logic
} else if (evt.getEntity() instanceof foo3) {
// do foo3 logic
}
Instead of each event being connected to the session, it could be connected with an specific Class (or set of classes or hierarchy of classes) in the hibernate mapping file.
Code:
public class FooFlush extends DefaultFlushEntityEventListener {
public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
if (evt.getEntity() instanceof foo) {
// do foo logic
}
}
}
public class Foo2Flush extends DefaultFlushEntityEventListener {
public void onFlushEntity(FlushEntityEvent evt) throws HibernateException {
if (evt.getEntity() instanceof foo2) {
// do foo2 logic
}
I think it's a quite obvious idea, Any comments ?