• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PostConstruct/PreDestroy of a Singleton should be executed in a transaction context

 
Himai Minh
Ranch Hand
Posts: 1360
7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On p.166 of Ivan's notes,

A transaction context is not available in all methods of EJBs. Examples of methods that execute in an unspecified transaction context include:
1. PostConstruct and PreDestroy methods in EJBs with container managed transactions.
2. PostConstruct and PreDestroy methods of singleton session beans.


For 1), according to the JSR-318, PostConstruct and PreDestroy lifecycle callback methods in stateful/stateless/ message driven bean are executed in unspecified transactional context.
But that does not include singleton.

For 2), according to session 4.8.3 of JSR-318, PostConstruct and PreDestroy methods of a Singleton with CMT are transactional. The transactional attributes are REQUIRED, REQUIRES_NEW or NOT_SUPPORTED.
That means these two methods are executed in
1 ) the client's transactional context;
2) or starts a new transaction while suspending the client's transaction
3) or not in any transactional context at all.

So, I think PostConstruct/PreDestroy methods of a singleton bean are not executed in an unspecified transaction context as described on p.166 of Ivan's notes.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2531
112
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I think PostConstruct/PreDestroy methods of a singleton bean are not executed in an unspecified transaction context as described on p.166 of Ivan's notes.

You are correct, those methods on a Singleton execute in a transaction context.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic