persistence@glassfish.java.net

RE: Re: Trting to add new child entity; getting OptimisticLockException

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Thu, 28 Sep 2006 10:30:44 -0400

Hello Ellen,
   In the constrctor of FileCategory is version being initialized to new Long(X) or being left as null?
--Gordon

-----Original Message-----
From: Ellen Kraffmiller [mailto:ekraffmiller_at_hmdc.harvard.edu]
Sent: Thursday, September 28, 2006 10:27 AM
To: persistence_at_glassfish.dev.java.net
Subject: Re: Trting to add new child entity; getting
OptimisticLockException


Hi Gordon,
I am working with Gustavo on this problem so I thought I'd answer your
questions. The version field is defined as:

  @Version
    private Long version;
(with normal getters and setters)

We are using SostgreSQL, and the database column is version, int8.

Thanks,
Ellen

Gordon Yorke wrote:

>Hello Gustavo,
> What is the version field in FileCategory being initialized to? What type is the version field?
>--Gordon
>
>-----Original Message-----
>From: gdurand_at_hmdc.harvard.edu [mailto:gdurand_at_hmdc.harvard.edu]
>Sent: Wednesday, September 27, 2006 5:57 PM
>To: persistence_at_glassfish.dev.java.net
>Subject: Trting to add new child entity; getting OptimisticLockException
>
>
>Hi,
>
>I'm am trying a very simple example and am getting a problem
>(I am using glassfish v2 milestone 1):
>
>Our DB has a Study entity which has a one to many relationship
>with a FileCategory entity.
>
>When I try to add a FileCategory to an existing study:
>
> Collection categories = study.getFileCategories();
>
> FileCategory c = new FileCategory();
> c.setName( "test" );
>
>
> c.setStudy(study);
> categories.add(c);
>
> em.merge(study);
>
>I am getting:
>
>Exception Details:
>oracle.toplink.essentials.exceptions.OptimisticLockException
> Exception Description: The object
>[edu.harvard.hmdc.vdcnet.study.FileCategory_at_1f1c748] cannot be merged
>because it has changed or been deleted since it was last read.
>{3}Class> edu.harvard.hmdc.vdcnet.study.FileCategory
>
>
>
>Any ideas why this is happening, since the FileCategory doesn't exist
>in the first place? (I have seen an example in the O'Reilly book that
>pretty much does just this)?
>
>Thanks,
>Gustavo
>
>
>
>
>
>