• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction attributes for private methods

 
Stephan Staeheli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it allowed and working correctly when I define a transaction attribute for a private method in my bean?

Stephan
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Transaction attribute can be defined for exposed public methods and not private methods but if a private method is invoked as a part of a public method the transaction context of the current public method will be applicable.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, keep in mind that you must make method calls on the component (remote or local) interface to have security and transaction attributes applied.

For example, say you have a bean with method A (never attribute) and method B (required attribute). Now if method A calls method B using standard Java "this.methodB()" notation, a transaction will not be started.

Instead, you must use something like "((BeanLocal) this.context.getEJBLocalObject()).methodB()". In words, you access the bean's component interface through the stored context, cast it to the correct interface, and call method B.
 
Stephan Staeheli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for your help. Especially to David, I just called the methods and wondered why there is no new transaction starting...

Regards,
Stephan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic