Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Detached Instance Following (read-only) Query(Recommended Practise: Detached Instance Following (read-only) Query)
Detached Instance Following (read-only) Query [message #801741] Sat, 18 February 2012 22:08 Go to next message
Marvin Toll is currently offline Marvin TollFriend
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 #804379 is a reply to message #801741] Wed, 22 February 2012 15:06 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

What is SOAj?


James : Wiki : Book : Blog : Twitter
Re: Detached Instance Following (read-only) Query [message #804438 is a reply to message #804379] Wed, 22 February 2012 16:21 Go to previous messageGo to next message
Marvin Toll is currently offline Marvin TollFriend
Messages: 34
Registered: July 2009
Member
- The Short Answer -
SOAj ( http://info.soaj ) is the reference implementation supporting "Pattern Enabled Development SM" ( http://PatternEnabled.com ).

- A More Complete Response -
These brief YouTube links might help:

http://youtu.be/-R-vA_Tc2fM

http://youtu.be/O6-zcR0XSmE

- More Importantly -
If our approach is to have all queries return Shared (Level 2) Cached instances... what is the best strategy for proceeding with an update based on an instance returned from a query?


Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
Re: Detached Instance Following (read-only) Query [message #804636 is a reply to message #804438] Wed, 22 February 2012 20:59 Go to previous messageGo to next message
Marvin Toll is currently offline Marvin TollFriend
Messages: 34
Registered: July 2009
Member
I'm now thinking that if queries are consistently configured for read-only... that all relationships [for example - @OneToOne(cascade=CascadeType.DETACH)] should be coded consistently. Anyone agree?


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 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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
Previous Topic:NPE in remote session
Next Topic:Recommended Practise: Consistent Timestamp for Unit of Work
Goto Forum:
  


Current Time: Thu Dec 05 10:02:53 GMT 2024

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

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

Back to the top