• 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

Doubt in interceptor methods

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a simple doubt in interceptors. The spec says we can have only one business method/life cycle interceptor on a given class.

Does that mean that, to have more than one interceptors we need to place them one in interceptor class, one in a bean, one in superclass.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessarily, you can have multiple interceptor classes. These will be called in order of their listing in DD or Annotation.
 
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We can have multiple interceptor methods. But if we create those not in the enterprise bean class, we can only have one interceptor method per class.
And then we register those class in our enterprise bean using @Interceptors.

Correct me if I am wrong.

regads,
daniel
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

We can have multiple interceptor methods. But if we create those not in the enterprise bean class, we can only have one interceptor method per class.



I think this is true only for Business Interceptor methods i.e. @aroundInvoke. However we can have multiple life cycle callbacks in one interceptor class using annotations @postCreate, @preDestroy, @postActivate, @prePassivate etc.

Similarly we can have only one business interceptor method in the bean class but multiple life cycle interceptor methods.
[ June 21, 2007: Message edited by: Ali Gohar ]
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just want to add this from the spec

However, a given class may not have more than one lifecycle callback interceptor method for the same lifecycle event.

 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Senthil for quoting that line from specs.

Only thing is if we define the lifecycle interceptor method eg: @PostDestroy in the business class can we redefine it in the interceptor class as well?

I suppose it should not be allowed. This needs to be confirmed.
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
shivani as per my understanding we can have more than one interceptor methods
for a life cycle event, provided they are in a separate class.

i don't think its redefining what is already there in a bean class. i guess that is the reason they have given the ordering of methods called, when multiple life cycle callback interceptors exists.

I am saying this just by reading the specs. Haven t tested it though.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Only thing is if we define the lifecycle interceptor method eg: @PostDestroy in the business class can we redefine it in the interceptor class as well?



Yes, we can define @PostDestroy both in Bean as well as separate interceptor class. As far as ordering is concerned, Bean class's callback will be called after the interceptor class's callback.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic