• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB 3.0 from O'Reilly

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

On page 77, it says,

The persist() method throws a TransactionRequiredException if this method is invoked on a transaction-scoped persistence context. Is this statement correct with respect to entities?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I expected, found this from the errata for the book,

http://oreilly.com/catalog/9780596009786/errata/9780596009786.unconfirmed
 
Santosh Raveendran
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jothi

can you please specify the complete name of the book you are referring.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Enterprise JavaBeans 3.0 (5th Edition), listed in the SCBCD Links
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jothi,

The persist() method throws a TransactionRequiredException if this method is invoked on a transaction-scoped persistence context.

what are your doubts about this statement ? The "correction" from O'Reilly sounds
{77} top paragraph;
the second sentence, "TransactionRequiredException is thrown if this method is invoked on a transaction-scoped persistence context." should be "TransactionRequiredException is thrown if this method is NOT invoked on a transaction-scoped persistence context."

This statement is definitely wrong! See JPA spec 3.1.1, page 47:
The persist, merge, remove, and refresh methods must be invoked within a transaction context when an entity manager with a transaction-scoped persistence context is used. If there is no transaction context, the javax.persistence.TransactionRequiredException is thrown.

If the entity manager uses an extended persistence context these methods can be called even without a transaction context.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To emphasize what Ralph says, 3.3 Persistence Context Lifetime says :
When an EntityManager with an extended persistence context is used, the persist, remove, merge, and refresh operations may be called regardless of whether a transaction is active. The effects of these operations will be committed to the database when the extended persistence context is enlisted in a transaction and the transaction commits.


I think they wanted to say : TransactionRequiredException is thrown if this method is NOT invoked within a transaction context when a transaction-scoped persistence context is used.
 
Ralph Jaus
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe, thanks for the link. I was shortly looking for it, but didn't found it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic