Detached Instance Following (read-only) Query [message #801741] |
Sat, 18 February 2012 22:08 |
Marvin Toll Messages: 34 Registered: July 2009 |
Member |
|
|
The SOAj implementation of EclipseLink includes the following in base class queries:
// This hint ensure that the shared instance be returned from cache.
query.setHint(QueryHints.READ_ONLY, HintValues.TRUE);
Therefore, what is the recommended practise to obtain a detached copy for updating a cached instance returned with a query? Is it?
persistenceResouceFacade.detach(myCachedInstanceOtainedViaQuery);
If so, what happens when two threads attempt to update and detach the same instance?
Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
|
|
|
|
|
|
Re: Detached Instance Following (read-only) Query [message #808370 is a reply to message #804636] |
Mon, 27 February 2012 18:08 |
|
You cannot (should not) modify read-only instances.
To update a read-only instance, you must,
- begin a transaction in the EntityMamnager
- register it with an EntityManager (em.find(), or em.merge())
- modify the object returned from the EntityManagers persistence context.
- commit the transaction in the EntityManager
If you want to be able to update the objects, then maybe read-only is not what you want. Perhaps just have some sort of singleton EntityManager that you read everything through to maintain object identity.
James : Wiki : Book : Blog : Twitter
|
|
|
Powered by
FUDForum. Page generated in 0.04107 seconds