Skip to main content

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

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


Back to the top