Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Entity callback doubt

 
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pg 55 EJB Persistence spec 3.4.4 Multiple Lifecycle Callback Methods for an Entity Lifecycle Event

"If a lifecycle callback method for the same lifecycle event is also specified on the entity class and/or one or more of its entity superclasses,the callback methods on the entity class and/or entity superclasses are
invoked after the other lifecycle callbackmethods,most general superclass first."

And in 3.4.5 example the output is as:
postPersistPetListenerMethod
postPersistCatListenerMethod
postPersistCatListener2Method
postPersistAnimal

Shouldnt the postPersistAnimal callbacke be called first?
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I was also confused about this. I understood as below.

Entity Animal does not have EntityListner associated with it.
Entity pet has PetListner.class as EntityListner
Cat has two EntityListners in the order CatListener.class and CatListener2.class

So the flow is like this
When @PostPersist event occurs on an instance of cat

the most general entity listener is PetListner and then are CatListener and CatListener2 and then comes the most general super class and then subclasses of it.

The same thing i found in Mikalais notes too. It says
" Entity listener method are invoked in a specific order when a given event occurs . Default listeners first if any , EntityListeners are invoked in the inheritance hierarchy and then super class listeners being invoked before subclass listeners"
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are callbacks in a listener treated differently or are listeners themselves treated differently for callbacks??
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

In ejb-3_0-fr-spec-ejbcore.pdf section 12.4.1 Multiple Callback Interceptor Methods for a Life Cycle Callback Event you can find the text:

"If there are any interceptor classes defined on the bean class, the lifecycle callback interceptor
methods defined by those interceptor classes are invoked before any lifecycle callback interceptor
methods defined on the bean class itself."

So any lifecycle callback interceptor defined in a separate class, not in the bean class, are called first. The superclasses external interceptors are called first.

That's why postPersistPetListenerMethod is called first because the Pet class is the first superclass which defines external interceptors.

postPersistAnimal is called last because is the only lifecycle callback defined inside the bean in the hierarchy.

Regards,
Ionut
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ionut,its clear now!!
 
Get me the mayor's office! I need to tell him about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic