Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA non-transactional method and entity access: Do I get a reference to the entity or a clone of the entity in the session cache?

In JPA you will always get a clone back from any find() or Query,

Unless:
- You mark the object as read-only (@ReadOnly annotation of orm.xml)
- You use the "eclipselink.read-only"="true" Query hint

I think it would also be useful to be able to get a read-only EntityManager
that always returns read-only objects, feel free to log an enhancement
request for this.  Perhaps a property like "eclipselink.read-only"="true"
when creating an EntityManager.



zebhed wrote:
> 
> This is a JPA-related question and a performance question.
> 
> I have an EJB that has a method annotated with
> "@TransactionAttribute(TransactionAttributeType.NEVER)". In this method, I
> am getting an entity via the EntityManager find() method. Let´s assume
> that this entity is already in the session cache.
> 
> The question is:
> Do I get a clone of the entity or do I get a reference to the entity that
> is in the session cache?
> 
> My assumption is that I get a reference to the entity that is in the
> session cache. There would be no need to clone an entity that cannot
> change.
> 
> Maybe someone can give some insight. Thanks.
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/JPA-non-transactional-method-and-entity-access%3A-Do-I-get-a-reference-to-the-entity-or-a-clone-of-the-entity-in-the-session-cache--tp22790869p22804933.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top