persistence icon indicating copy to clipboard operation
persistence copied to clipboard

more flexible application of entity listeners to entities

Open gavinking opened this issue 1 month ago • 1 comments

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:

  1. Allow @EntityListeners at the PACKAGE level, to apply to all @Entity classes in the package.
  2. Allow use of @EntityListeners as a meta-annotation, as proposed by #43.
  3. Add a new @EntityListener annotation, 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.

gavinking avatar Nov 26 '25 20:11 gavinking