File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple postconstruct and predestroy methods.

 
Deepak Jain
Ranch Hand
Posts: 637
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have multiple PostConstruct and PreDestroy callbacks for a given bean.


PlaceBidBean has two PostConstruct callbacks initBean() and initializeBean().
Exception:
17:37:54,031 WARN [ServiceController] Problem starting service jboss.j2ee:service=EJB3,module=myEJB-ejb.jar
java.lang.RuntimeException: An exception occurred initialising interceptors for class com.ejb3inaction.actionbazaar.buslogic.PlaceBidBean.addBid
at org.jboss.ejb3.interceptor.EJB3InterceptorsFactory.createPerJoinpoint(EJB3InterceptorsFactory.java:108)
at org.jboss.aop.advice.AspectFactoryDelegator.createPerJoinpoint(AspectFactoryDelegator.java:119)
at org.jboss.aop.advice.ScopedInterceptorFactory.create(ScopedInterceptorFactory.java:113)
at org.jboss.aop.Advisor.createInterceptorChain(Advisor.java:618)
Caused by: java.lang.RuntimeException: Interceptors can only have one post-construct/@PostConstruct method - com.ejb3inaction.actionbazaar.buslogic.PlaceBidBean
at org.jboss.ejb3.interceptor.InterceptorInfo.setPostConstruct(InterceptorInfo.java:147)
at org.jboss.ejb3.interceptor.InterceptorInfoRepository$AnnotationInitialiser.getInfo(InterceptorInfoRepository.java:688)
at org.jboss.ejb3.interceptor.InterceptorInfoRepository.initialiseFromAnnotations(InterceptorInfoRepository.java:481)
at org.jboss.ejb3.interceptor.InterceptorInfoRepository.getOrInitialiseFromAnnotations(InterceptorInfoRepository.java:466)

1) Why multiple callbacks are not allowed for stateless session bean?
2) I dont understand why the exception has "Interceptors" words. I have just used a plain stateless session bean as shown in the code.
Please clarify.
What about PreDestroy, PrePassivate and PostActivate callbacks?
3) Is the book incorrect?
 
LakshmiNarayana Kodali
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have mutiple callbacks for a given bean.It is correct.

But the condition is you cannot define mutiple callback methods for a single lifecycle event in a Single bean class


Ex. In the above example, you mentioned 2 callback methods initBean() and initializeBean() for a PostConstuct event in 1 bean class PlcaeBidBean. This is wrong


However you can remove the one of the postConstruct methods and can put it in bean superclass or also in Bean Interceptor classes so that both methods will be called.

Simply to say, atmost 1 lifecycle callback method should be declared for each lifecycle event in each class ( it can be bean class or its super class or its interceptor class)


2. Lifecycle callback methods are also called as lifecycle callback interceptor methods.
I think because of that the exception has "Interceptors" words. Not sure

3. EJB3 in Action is really good book for EJB3 beginners. The authors did an excellent work.
The points mentioned by the authors are from the Specs only.
But there are few concepts which they need to explain clearly.

I looked at the questions raised by you. Really good. I'm also looking for answers for some questions. Let's see

-------------------------------------
LakshmiNarayana Kodali
SCJP 5(98%), SCWCD(100%), SCBCD in progress
 
Deepak Jain
Ranch Hand
Posts: 637
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

EJB3 in Action is really good book for EJB3 beginners. The authors did an excellent work. The points mentioned by the authors are from the Specs only.
But there are few concepts which they need to explain clearly.


Please don't get me wrong. I highly appreciate their work. Infact am reading EJB in Action to understand about EJB. Before reading the book i had 0 knowledge on EJB.
 
Marcin Faryna
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes in "EJB in Action" (2007) is written "Note that you can have multiple PostConstruct and PreDestroy callbacks for a given bean (although this is seldom used) in a class or in a separate interceptor class (discussed in chapter 5)." . Which can direct to the false assumption that in single class definition you can have more then one @PostConstruct and @PreDestroy annotated method.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic