Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] OrderColumn and OneToMany issue in eclipselink...

You code seems very complex with the detaching and I assume merging, what are
you trying to accomplish?  Why not just change the objects and commit?

What does createOrUpdateObject() and detach() do?  Where do you get your
EntityManager from.  In the container it will be JTA managed most likely, so
each new transaction will be a different persistence context.

JBoss also does not allow weaving, so your LAZY annotation may not be
working, this may cause the merge to merge additional objects.  You may want
to use static weaving.

Also enable logging and include the log.



vaidya nathan wrote:
> 
> I have the following entities that i want to persist. The Categories
> is just a wrapper to preserve the order of Category and we preserve it
> in the DB by using OrderColumn
> 
> @Entity(name="CATS")
> public class Categories
> {
> 
>    @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
>     @OrderColumn(name="POS")
>     @JoinTable(name="CATS_CAT",
> joinColumns=@JoinColumn(name="CATS_ID"),
> inverseJoinColumns=@JoinColumn(name="CATEGORIES_ID"))
>     @IndexColumn(name="POS", base=0)
>     @PrivateOwned
>    private List<Category> categories ;
> }
> 
> @Entity
> @Table(name="CAT")
> public class Category
> {
>   private String name;
> }
> 
> 
> My DAO method is as follows
> 
> public List<Category> updateBusinessCategories(List<Category> cats)
> throws DAOException
>     {
>         try
>         {
>           ReadObjectQuery busCatQuery=new ReadObjectQuery();
>           busCatQuery.setReferenceClass(Categories.class);
>           Categories bizcats = getObject(busCatQuery) ;
>           detach(bizcats);
> 
>           for (Category bc: cats)
>           {
>             detach(bc);
>           }
> 
>           bizcats.setCategories(cats) ;
>           bizcats = createOrUpdateObject(bizcats) ;
>           cats = bizcats.getCategories() ;
>        }
>        catch (Exception e)
>        {
>          throw new DAOException(e) ;
>        }
>        return cats ;
>     }
> 
> This code runs good in a pojo environment , however when i run it in
> the jboss container I get the following exceptions
> Exception Description: The object [Categories@1] cannot be updated
> because it has changed or been deleted since it was last read.
> Class> Categories Primary Key> 1
> 	at
> org.eclipse.persistence.exceptions.OptimisticLockException.objectChangedSinceLastReadWhenUpdating(OptimisticLockException.java:137)
> 	at
> org.eclipse.persistence.descriptors.VersionLockingPolicy.validateUpdate(VersionLockingPolicy.java:778)
> 	at
> org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1050)
> 	at
> org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)
> 	
> 
> When i take off the detach , i get the following
> Exception [EclipseLink-5006] (Eclipse Persistence Services -
> 2.3.2.v20111125-r10461):
> org.eclipse.persistence.exceptions.OptimisticLockException
> Exception Description: The object [aa2] cannot be updated because it
> has changed or been deleted since it was last read.
> Class> Category Primary Key> 2
> 	at
> org.eclipse.persistence.exceptions.OptimisticLockException.objectChangedSinceLastReadWhenUpdating(OptimisticLockException.java:137)
> 	at
> org.eclipse.persistence.descriptors.VersionLockingPolicy.validateUpdate(VersionLockingPolicy.java:778)
> 	at
> org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.updateObjectForWriteWithChangeSet(DatabaseQueryMechanism.java:1050)
> 	at
> org.eclipse.persistence.queries.UpdateObjectQuery.executeCommitWithChangeSet(UpdateObjectQuery.java:84)
> 	
> where aa2 is an existing category..
> 
> I tried cloning too just before the update but that is not helping
> either.. What do i need to do update the Category items that are
> managed by the Categories.. ? I would prefer not doing a detach .
> 
> Thx
> Vaidya
> 
> 


-----
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.eclipse.org/forums/index.php?t=thread&frm_id=111&S=1b00bfd151289b297688823a00683aca
EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/OrderColumn-and-OneToMany-issue-in-eclipselink...-tp34086405p34086705.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top