• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Timer cannot be created in @PostConstruct using BMT ?

 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The objective is to create a Timer in @PostConstruct of a Stateless bean using BMT:


I got this:

Warning: A system exception occurred during an invocation on EJB StatelessSessionBeanA method public void com.ivan.scbcd6.StatelessSessionBeanA.method1()
javax.ejb.EJBException: Stateless SessionBean method returned without completing transaction
at com.sun.ejb.containers.BaseContainer.checkExceptionBeanMgTx(BaseContainer.java:4973)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4844)
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if I create the Timer in a business method in the above bean, the timer can be created.


I understand the fact that @PostConstruct should be called in an unspecified transaction context, but the user transaction should suspend any transaction.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you create the timer without a transaction in the @PostConstruct method, does that work?
 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By default, the transaction management is Container Managed Transaction.
I tried to create the time in @PostConstruct method.
For stateless bean the @PostConstruct method is implemented in an unspecified transaction context and the timer must be created in a transaction with attribute (REQUIRED or REQUIRED_NEW).
The timer is not created.



Info: *** StatelessSessionBeanA - initialized
Severe: EJB5070: Exception creating stateless session bean : [StatelessSessionBeanA]
Warning: A system exception occurred during an invocation on EJB StatelessSessionBeanA method public void com.ivan.scbcd6.StatelessSessionBeanA.method1()
javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
...
Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
...
Caused by: javax.ejb.CreateException: Could not create stateless EJB
...
Caused by: java.lang.IllegalStateException: EJB Timer method calls cannot be called in this context
.....


 
Himai Minh
Ranch Hand
Posts: 1361
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the timer can be created with a singleton bean.
The timer is created within a user managed transaction in @PostConstruct.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic