Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Duplicate Entities in GlassFish Persistence Context - see 337080

Bernard,
    This duplicate entity issue has come up before.  Mitesh triaged it and discovered that the annotation below was the cause.  By changing from the NOT_REQUIRED
transaction type - which suspends the transaction for the life of the method it annotates - to the default REQUIRED.

@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)

https://bugs.eclipse.org/bugs/show_bug.cgi?id=337080
http://books.google.com/books?id=fVCuB_Xq3pAC&pg=PA124&lpg=PA124&dq=default+TransactionAttributeType&source=bl&ots=BgeE8gWJVU&sig=JQ47t7SUmFrRGfFvrfVImhTVLuY&hl=en&ei=r8BuTbfBOIGmsQPCsK2FDg&sa=X&oi=book_result&ct=result&resnum=7&ved=0CDYQ6AEwBg#v=onepage&q=default%20TransactionAttributeType&f=false
   Just an fyi.
    /Michael



On 02/03/2011 13:13, bht@xxxxxxxxxxxxx wrote:
Hi James,

It was within a single session bean method.

However, the method was annotated with
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)

and I overlooked that.
    
Many thanks,

Bernard

On Wed, 2 Mar 2011 07:33:06 -0800 (PST), you wrote:

  
Within a JTA transaction the EntityManager must always return the same
instance (unless you call clear).

Are you sure it is a single transaction?  Or is it two different
transactions, or not in a JTA transaction context?  With a JTA managed
EntityManager a different instance must be return across each transaction
boundary.

Ensure you are in a single transaction and are not calling clear, perhaps
enable logging on finest.


bht wrote:
    
Hi,

I am getting duplicate managed Entities in EntityManager in a single
transaction.

This happens only in GlassFish, not with a JUnit test that uses
transaction-type="RESOURCE_LOCAL" in persistence.xml.

After retrieveal from an object query, the same entities are looked up
again using EntityManager.find().

find() gets the duplicates. I spotted them because they "lost" some
transient fields that were set prior to find(), and they have
different Object hashcodes.

One could argue that there is no contract that stipulates that
EntityManager must return identical entities for the same entity type
and ID within the same transaction.

However, there is also no reason for such a waste of memory because if
I can compare them, then I have the references to them and they cannot
be garbage collected anyway.

Is this a bug? Should I report this?

The scenario is very difficult to deal with - it limits my programming
options quite a bit. It is scary and frustrating.

Regards,

Bernard


      
-----
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 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
    
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  

Back to the top