| Author |
EJB 3.0 from O'Reilly
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
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?
|
SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
As I expected, found this from the errata for the book,
http://oreilly.com/catalog/9780596009786/errata/9780596009786.unconfirmed
|
 |
Santosh Raveendran
Ranch Hand
Joined: Jun 29, 2008
Posts: 83
|
|
jothi
can you please specify the complete name of the book you are referring.
|
SCJP 1.4,SCWCD5, SCBCD5
Thanks, Santhosh
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
|
Enterprise JavaBeans 3.0 (5th Edition), listed in the SCBCD Links
|
[My Blog]
All roads lead to JavaRanch
|
 |
Ralph Jaus
Ranch Hand
Joined: Apr 27, 2008
Posts: 342
|
|
Hi Jothi,
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.
|
SCJP 5 (98%) - SCBCD 5 (98%)
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
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
Joined: Apr 27, 2008
Posts: 342
|
|
Christophe, thanks for the link. I was shortly looking for it, but didn't found it.
|
 |
 |
|
|
subject: EJB 3.0 from O'Reilly
|
|
|