Question

Why do we need Java Persistence API listeners when callbacks and listeners are the same in...

Why do we need Java Persistence API listeners when callbacks and listeners are the same in functionality?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q Why do we need Java Persistence API listeners when callbacks and listeners are the same in functionality?

Well we use Java Persistence API listeners when callbacks and listeners are the same in functionality because we can define several entity Persistence API listeners per entity at respected levels of the hierarchy. We can also show or define various callbacks at every different level of the hierarchy. But we are not able to define two API listeners for the same event in the same entity or the same entity API listener.

When an event is invoked, the listeners are executed in this order:

  • EntityListeners for a given entity or superclass in order

  • Entity listeners for the super-classes (staring with highest order)

  • Entity Listeners for the entity

  • Callbacks of the super-classes (Higer will be first)

  • Callbacks of the entity

We can stop the entity API listeners inheritance by using the @ExcludeSuperclassListeners, all superclasses EntityListeners will then be ignored. So its is necessary to use API listeners.

Add a comment
Know the answer?
Add Answer to:
Why do we need Java Persistence API listeners when callbacks and listeners are the same in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT