• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Override Entity Callback Method

 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The mikalai Zaikin Notes States
"A class is permitted to override an inherited callback method of the same callback type, and in this case, the overridden method is NOT invoked."
However in the example given, the overriden method is invoked...
@Entity
public class Animal {
....
@PostPersist
protected void postPersistAnimal() {
System.out.println("Inside Animal.postPersistAnimal()");
}
}

@Entity
@EntityListeners({CatListener.class, CatListener2.class})
public class Cat extends Pet {
...
}

@EntityListeners(SiameseCatListener.class)
@Entity
public class SiameseCat extends Cat {
...
@PostPersist
protected void postPersistAnimal() {
System.out.println("Inside SiameseCat.postPersistAnimal()");
}
}

Here the overridden method SiameseCat.postPersistAnimal() is called and Animal.postPersistAnimal() is not at all called.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sandeep Vaid wrote:Here the overridden method SiameseCat.postPersistAnimal() is called and Animal.postPersistAnimal() is not at all called.



The overriden method is Animal.postPersistAnimal() not the SiameseCat.postPersistAnimal()

Animal.postPersistAnimal() -> overridden method
SiameseCat.postPersistAnimal() -> overriding method
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah.. Yes. thanks tom.
reply
    Bookmark Topic Watch Topic
  • New Topic