more flexible application of entity listeners to entities
This issue follows up on the very ancient issue #43.
Something I guess nobody has ever liked is the @EntityListeners annotation, which is sort-of backwards, or at least lacking in indirection. After #687 and #730, entity listeners are already starting to look quite a lot more flexible, and so this sticks out worse than it did before.
I think we should consider a range of ways to address this, not just what's proposed in #43. Off the top of my head, I can think of the following straightforward approaches:
- Allow
@EntityListenersat thePACKAGElevel, to apply to all@Entityclasses in the package. - Allow use of
@EntityListenersas a meta-annotation, as proposed by #43. - Add a new
@EntityListenerannotation, taking a list of classes the listener applies to, including the possibility of super types, so that@EntityListener(Object.class) class MyListener { ... }would declare a listener that applies to all entity types.
These options are not mutually-exclusive, and my knee-jerk prejudice is that I would sorta like to do 2+3. Option 2 works rather nicely
But I would like to hear some feedback on this before writing up a proposal.