You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by areider <op...@reider.net> on 2011/11/08 00:27:23 UTC

TransactionRequiredException on persist on extended EM?

I've seen  a TransactionRequiredException error occur on persist() when no
transaction is active, for an extended persistence context. jsr220 states,
in 3.1.1:

/*
 * @throws TransactionRequiredException if invoked on a
 * container-managed entity manager of type
 * PersistenceContextType.TRANSACTION and there is
 * no transaction 
*/

In 3.3 it states:
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. 

However, in the OpenJPA documention at
http://openjpa.apache.org/builds/apache-openjpa-1.2.3-SNAPSHOT/docs/manual/manual.html#jpa_overview_em_trans


it states:

This action  [persist] can only be used in the context of an active
transaction.

without any qualification as to the persistenceContextType of the entity
manager.

Is OpenJPA in compliance with the spec here?


--
View this message in context: http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6972526.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: TransactionRequiredException on persist on extended EM?

Posted by Kevin Sutter <kw...@gmail.com>.
Excellent.  Thanks for the reply.

On Tue, Nov 8, 2011 at 10:15 AM, areider <op...@reider.net> wrote:

> Kevin,
>
> >> Well, you didn't mention that you had a test case that proved
> >> otherwise...
> :-)
>
> My fault sorry, working as advertised. (that is, if there is no active
> transaction and the context is extended, then no error is thrown)
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6974888.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: TransactionRequiredException on persist on extended EM?

Posted by areider <op...@reider.net>.
Kevin,

>> Well, you didn't mention that you had a test case that proved
>> otherwise...
:-)

My fault sorry, working as advertised. (that is, if there is no active
transaction and the context is extended, then no error is thrown)

--
View this message in context: http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6974888.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: TransactionRequiredException on persist on extended EM?

Posted by Kevin Sutter <kw...@gmail.com>.
Well, you didn't mention that you had a test case that proved otherwise...
:-)  I thought you were just asking about the documentation.

If your assessment is accurate, then this sounds like a spec compliance
issue -- which I am surprised hasn't been discovered until now.  If you
could package together a simple junit testcase that demonstrates this
scenario, then we should take a closer look.  A JIRA [1] would also be
good, if you access to that.

Thanks,
Kevin

[1]  http://issues.apache.org/jira/browse/OPENJPA

On Mon, Nov 7, 2011 at 5:59 PM, areider <op...@reider.net> wrote:

> Kevin,
>
> I can see that interpretation, but I'm not only going by the doc,  it
> actually seems to be doing that validation at persist() time and throwing
> the TransactionRequiredException, even though the em is marked as
> persistenceContextType.EXTENDED... so unless i'm missing something, it
> seems
> as if it is doing the transaction-required check when it shouldn't be ...
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6972602.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: TransactionRequiredException on persist on extended EM?

Posted by areider <op...@reider.net>.
Kevin,

I can see that interpretation, but I'm not only going by the doc,  it
actually seems to be doing that validation at persist() time and throwing
the TransactionRequiredException, even though the em is marked as 
persistenceContextType.EXTENDED... so unless i'm missing something, it seems
as if it is doing the transaction-required check when it shouldn't be ...


--
View this message in context: http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6972602.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: TransactionRequiredException on persist on extended EM?

Posted by Kevin Sutter <kw...@gmail.com>.
Hi areider,
I think you have to take your OpenJPA manual reference in context of the
overall actions being described.  In each of these sub-sections on persist,
remove, etc, there is mention of the "next flush or commit".  The persist()
invocation by itself does not interact with the database.  That doesn't
happen until the flush or commit is performed.  At which time, some type of
transaction is necessary in order to complete the operation against the
database.

So, if you combine the em.persist() invocation and the transaction context
as the "action", then this statement you referenced is accurate:  "This
action can only be used in the context of an active
transaction."

You might say that I'm splitting hairs, but I believe that was the intent
of the description.

Kevin


On Mon, Nov 7, 2011 at 5:27 PM, areider <op...@reider.net> wrote:

> I've seen  a TransactionRequiredException error occur on persist() when no
> transaction is active, for an extended persistence context. jsr220 states,
> in 3.1.1:
>
> /*
>  * @throws TransactionRequiredException if invoked on a
>  * container-managed entity manager of type
>  * PersistenceContextType.TRANSACTION and there is
>  * no transaction
> */
>
> In 3.3 it states:
> 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.
>
> However, in the OpenJPA documention at
>
> http://openjpa.apache.org/builds/apache-openjpa-1.2.3-SNAPSHOT/docs/manual/manual.html#jpa_overview_em_trans
>
>
> it states:
>
> This action  [persist] can only be used in the context of an active
> transaction.
>
> without any qualification as to the persistenceContextType of the entity
> manager.
>
> Is OpenJPA in compliance with the spec here?
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/TransactionRequiredException-on-persist-on-extended-EM-tp6972526p6972526.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>