Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sessionSynchronization

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't statless bens implement sessionSynchronization?

Can BMT Session beans implement sessionSynchronization? It would be pointless but can they?

Can EntityBeans implement sessionSynchronization?
 
Paul Codillo
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kris Reid:
Why can't statless bens implement sessionSynchronization?
Can BMT Session beans implement sessionSynchronization? It would be pointless but can they?
Can EntityBeans implement sessionSynchronization?

1.) Stateless beans cannot implement sessionSynchronization because transactions in stateless session beans are not allowed to span multiple method calls. As soon as a method returns, the transaction is over. Begin/Commit is governed by the scope of the method. There is no more sense to call the sessionSynchronization methods.
2.) They can (im not sure) but might not be called by the container since it expects the bean provider to explicitly call begin and commit.
3.) Entitiy beans have onLoad() and onStore() methods instead of the sessionSynchronization methods. I'm not sure if implementing is legal. I doubt it.
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't stateless beans implement SessionSynchronization?

By allowing stateless session beans to implement SessionSynchronization, we're actually implying that session beans can maintain state across transactions, which is not true. Hence, it is not allowed.

Can BMT Session beans implement SessionSynchronization? It would be pointless but can they?

You can't. Because by having BMT, you know exactly when you're starting & ending the transactions. The exact boundaries of the transactions are made known to you. Hence, you don't have to rely on implementing the SessionSynchronization interface.

Can EntityBeans implement SessionSynchronization?

As of EJB 2.0, entity beans can only be of CMT type. As pointed out by Paul, you've the benefits of ejbLoad & ejbStore. Also, the name of the interface sortof indicated that its meant for session beans only.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic