openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin Sutter" <kwsut...@gmail.com>
Subject Re: should EntityManager.refresh require active transaction? or not?
Date Thu, 23 Oct 2008 18:00:16 GMT
The JPA spec is pretty clear on the requirements.  First from the javadoc
for the EM.refresh() method:

/**
* Refresh the state of the instance from the database,
* overwriting changes made to the entity, if any.
* @param entity
* @throws IllegalArgumentException if not an entity
* or entity is not managed
** @throws TransactionRequiredException if invoked on a*
** container-managed entity manager of type*
** PersistenceContextType.TRANSACTION and there is*
** no transaction.*
* @throws EntityNotFoundException if the entity no longer
* exists in the database
*/
public void refresh(Object entity);

And, then in the same section, the following explanation on when
transactions are required or not:

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.

So, it would seem that if you are using EM.refresh() outside a
container-managed EM with transaction-scoped persistence context, then you
should not require a Transaction.  And, if you are getting an exception,
then that sounds like a bug.  Unless I am not understanding your scenario...

Kevin

On Thu, Oct 23, 2008 at 12:17 PM, Fernando Padilla <fern@alum.mit.edu>wrote:

> oh.  that's interesting.  A slight difference in point of view.  I don't
> see those "changes" as changes that are to be tracked within a transaction,
> since those changes are not to be applied to the database ever.. they are
> just refreshing your view of the authoritative version in the db..
>
> do you think your decision is a technical one, or just a philosophical one?
>
>
>
>
> Pinaki Poddar wrote:
>
>> as refresh() may result into overwriting the state of the persistence
>> instance, if invoked outside a transaction then following must be set
>>   <property name="openjpa.NontransactionalWrite" value="true"/>
>>
>>
>>
>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message