Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TransactionRequiredException in Entities

 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

The information given in the EJB 3 book from O'Reilly on page 80 says that the TransactionRequiredException is thrown when the method that does either update, merge operation on an Entity is called on a transaction-scoped persistence context. I guess it should be the opposite way. Is this an errata in the book?
 
Treimin Clark
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jothi Shankar Kumar wrote:Guys,

The information given in the EJB 3 book from O'Reilly on page 80 says that the TransactionRequiredException is thrown when the method that does either update, merge operation on an Entity is called on a transaction-scoped persistence context. I guess it should be the opposite way. Is this an errata in the book?


I think it is not an errata. When invoked those methods on an EntityManager with transaction-scoped persistence context, without having a transaction (EntityTransaction.begin() method), it will throw the TransactionRequiredException.

Read the documentation.


Please correct me, if I'm wrong.
 
Joe Harry
Ranch Hand
Posts: 10091
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The example in the book has a method that has a transaction scoped persistence context followed by this line as posted above which is quite contradictory.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic