Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Exception when updating object from outside of transaction
Exception when updating object from outside of transaction [message #1286920] Mon, 07 April 2014 07:39 Go to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 6
Registered: November 2012
Junior Member
When DB object is queried from DB and accidentally updated from outside of transaction nothing happens: neither new value(s) are stored in DB (which is obvious) nor any exception is thrown.

Is there any way to force EL to thrown such exception?
Re: Exception when updating object from outside of transaction [message #1290942 is a reply to message #1286920] Thu, 10 April 2014 15:24 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Can you explain a bit futher on what you mean? EntityManager returns managed entities, but they are regular java objects that you are allowed to make changes to. You would only get those changes sychronized to the database if the EntityManager is flushed or the associated transaction (if there were one) commited. If you expect changes to be synchronized, calling flush will throw an exception if called outside a transaction; otherwise the EntityManager is required to hold onto changes until it is associated to a transaction (or until it is cleared or closed).
Re: Exception when updating object from outside of transaction [message #1298665 is a reply to message #1290942] Wed, 16 April 2014 12:11 Go to previous messageGo to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 6
Registered: November 2012
Junior Member
No Message Body
Re: Exception when updating object from outside of transaction [message #1298666 is a reply to message #1286920] Wed, 16 April 2014 12:13 Go to previous messageGo to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 6
Registered: November 2012
Junior Member
Here is example:

Lets say that dbObject stored in DB and it has id = 1 and name = "fresh_object".
Open EntityManager

DBObject dbObject = em.find(DBObject.class, 1);
dbObject.setName("updated_object");

Close EntityManger


Now, if we check that object in DB, its name will still be "fresh_object" - which is obvious, because there wasn't any transaction.

In the past, when we used OpenJPA 1.2.3, exception was thrown during name setting:
<openjpa-1.2.3-SNAPSHOT-r422266:1086217 nonfatal user error> org.apache.openjpa.persistence.InvalidStateException: To perform writes on persistent data outside of a transaction, the "NontransactionalWrite" property must be set to true.

link to NontransactionalWrite property doc

Now, I'd like to have the same behaviour in EclipseLink. Is it possible?
Re: Exception when updating object from outside of transaction [message #1324114 is a reply to message #1298666] Wed, 30 April 2014 16:14 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
There is no such property I'm aware of in EclipseLink. With JPA, you should be calling flush() which will indicate to the provider that it should write out changes, and will cause the desired exception if done outside a transaction.
Previous Topic:Include json.root element as a @type attribute
Next Topic:Unique constraints in unidirectional one to one relationship
Goto Forum:
  


Current Time: Fri Nov 28 14:56:10 GMT 2014

Powered by FUDForum. Page generated in 0.02529 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software