You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Tim Watts <ti...@earthlink.net> on 2008/01/26 04:16:27 UTC

merge() is inserting when it should be updating

Hi,

My OpenJPA app inserts the entity correctly the 1st time, but when it's 
updated, it tries to insert it again causing a data integrity exception. See 
the exception message below. I'm using em.merge() to do the update (as well 
as the initial add). The entity key does not change between the add and 
update.

Can anyone offer some suggestions as to what would cause a situation like 
this? Anyone else run across this? How did you fix it?

I'm using OpenJPA 1.0.1 with Derby 10.2.2.0 and Spring's JPA support (2.0.7)

ROOT CAUSE EXCEPTION MESSAGE
----------------------------
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The statement 
was aborted because it would have caused a duplicate key value in a unique or 
primary key constraint or unique index identified by 'SQL071203083750550' 
defined on 'CRUNCHERINFO'. {prepstmnt 18605439 INSERT INTO CruncherInfo 
(serviceURL, accessKey, adminUrl, agentId, commonName, lastRegistration, 
osname, SERVICE_VALUE, state, stateKey, CRUNCHERSTATUS_VALUE) VALUES 
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(String) 
http://dellberry.cliftonfarm.net:7302, (String) bogus-accesskey, (String) 
http://dellberry.cliftonfarm.net:6322, (String) dellberry.cliftonfarm.net, 
(String) TestName_1, (Timestamp) 2008-01-25 21:02:09.512, (String) Linux, 
(String) TESTTYPE, (String) STOPPED, (String) cruncher.state.stopped, 
(String) DEAUTHORIZED]} [code=20000, state=23505]

----------------------------
BTW: SQL071203083750550 is:

ALTER TABLE "APP"."CRUNCHERINFO" ADD CONSTRAINT "SQL071203083750550" PRIMARY 
KEY ("SERVICEURL");

Re: merge() is inserting when it should be updating

Posted by Tim Watts <ti...@earthlink.net>.
Yep, 1.0.2 fixed it! 

Thanks again.

On Friday 25 January 2008 11:27 pm, Tim Watts wrote:
> Hi,
>
> I'm creating a new record and merging that. However, it does load the
> existing record into a different instance of the class and may copy a field
> from that instance to the new record.
>
> I'll give the new versions a try.
>
> Thanks Patrick.
>
> On Friday 25 January 2008 10:24 pm, Patrick Linskey wrote:
> > How are you getting the records to merge? Are you creating a new
> > record and changing values, or are you getting the records from a
> > previous EntityManager and then calling merge() on them? If the
> > former, then in normal configurations, then you might want to try out
> > a recent 1.1.0 or 1.0.2 snapshot; we just resolved an issue related to
> > that behavior this week.
> >
> > -Patrick
> >
> > On Jan 25, 2008 7:16 PM, Tim Watts <ti...@earthlink.net> wrote:
> > > Hi,
> > >
> > > My OpenJPA app inserts the entity correctly the 1st time, but when it's
> > > updated, it tries to insert it again causing a data integrity
> > > exception. See the exception message below. I'm using em.merge() to do
> > > the update (as well as the initial add). The entity key does not change
> > > between the add and update.
> > >
> > > Can anyone offer some suggestions as to what would cause a situation
> > > like this? Anyone else run across this? How did you fix it?
> > >
> > > I'm using OpenJPA 1.0.1 with Derby 10.2.2.0 and Spring's JPA support
> > > (2.0.7)
> > >
> > > ROOT CAUSE EXCEPTION MESSAGE
> > > ----------------------------
> > > Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The
> > > statement was aborted because it would have caused a duplicate key
> > > value in a unique or primary key constraint or unique index identified
> > > by 'SQL071203083750550' defined on 'CRUNCHERINFO'. {prepstmnt 18605439
> > > INSERT INTO CruncherInfo (serviceURL, accessKey, adminUrl, agentId,
> > > commonName, lastRegistration, osname, SERVICE_VALUE, state, stateKey,
> > > CRUNCHERSTATUS_VALUE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> > > [params=(String)
> > > http://dellberry.cliftonfarm.net:7302, (String) bogus-accesskey,
> > > (String) http://dellberry.cliftonfarm.net:6322, (String)
> > > dellberry.cliftonfarm.net, (String) TestName_1, (Timestamp) 2008-01-25
> > > 21:02:09.512, (String) Linux, (String) TESTTYPE, (String) STOPPED,
> > > (String) cruncher.state.stopped, (String) DEAUTHORIZED]} [code=20000,
> > > state=23505]
> > >
> > > ----------------------------
> > > BTW: SQL071203083750550 is:
> > >
> > > ALTER TABLE "APP"."CRUNCHERINFO" ADD CONSTRAINT "SQL071203083750550"
> > > PRIMARY KEY ("SERVICEURL");

-- 
"Absolute security comes with chains."

Re: merge() is inserting when it should be updating

Posted by Tim Watts <ti...@earthlink.net>.
Hi,

I'm creating a new record and merging that. However, it does load the existing 
record into a different instance of the class and may copy a field from that 
instance to the new record. 

I'll give the new versions a try.

Thanks Patrick.

On Friday 25 January 2008 10:24 pm, Patrick Linskey wrote:
> How are you getting the records to merge? Are you creating a new
> record and changing values, or are you getting the records from a
> previous EntityManager and then calling merge() on them? If the
> former, then in normal configurations, then you might want to try out
> a recent 1.1.0 or 1.0.2 snapshot; we just resolved an issue related to
> that behavior this week.
>
> -Patrick
>
> On Jan 25, 2008 7:16 PM, Tim Watts <ti...@earthlink.net> wrote:
> > Hi,
> >
> > My OpenJPA app inserts the entity correctly the 1st time, but when it's
> > updated, it tries to insert it again causing a data integrity exception.
> > See the exception message below. I'm using em.merge() to do the update
> > (as well as the initial add). The entity key does not change between the
> > add and update.
> >
> > Can anyone offer some suggestions as to what would cause a situation like
> > this? Anyone else run across this? How did you fix it?
> >
> > I'm using OpenJPA 1.0.1 with Derby 10.2.2.0 and Spring's JPA support
> > (2.0.7)
> >
> > ROOT CAUSE EXCEPTION MESSAGE
> > ----------------------------
> > Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The
> > statement was aborted because it would have caused a duplicate key value
> > in a unique or primary key constraint or unique index identified by
> > 'SQL071203083750550' defined on 'CRUNCHERINFO'. {prepstmnt 18605439
> > INSERT INTO CruncherInfo (serviceURL, accessKey, adminUrl, agentId,
> > commonName, lastRegistration, osname, SERVICE_VALUE, state, stateKey,
> > CRUNCHERSTATUS_VALUE) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
> > [params=(String)
> > http://dellberry.cliftonfarm.net:7302, (String) bogus-accesskey, (String)
> > http://dellberry.cliftonfarm.net:6322, (String)
> > dellberry.cliftonfarm.net, (String) TestName_1, (Timestamp) 2008-01-25
> > 21:02:09.512, (String) Linux, (String) TESTTYPE, (String) STOPPED,
> > (String) cruncher.state.stopped, (String) DEAUTHORIZED]} [code=20000,
> > state=23505]
> >
> > ----------------------------
> > BTW: SQL071203083750550 is:
> >
> > ALTER TABLE "APP"."CRUNCHERINFO" ADD CONSTRAINT "SQL071203083750550"
> > PRIMARY KEY ("SERVICEURL");

-- 
"Absolute security comes with chains."

Re: merge() is inserting when it should be updating

Posted by Patrick Linskey <pl...@gmail.com>.
How are you getting the records to merge? Are you creating a new
record and changing values, or are you getting the records from a
previous EntityManager and then calling merge() on them? If the
former, then in normal configurations, then you might want to try out
a recent 1.1.0 or 1.0.2 snapshot; we just resolved an issue related to
that behavior this week.

-Patrick

On Jan 25, 2008 7:16 PM, Tim Watts <ti...@earthlink.net> wrote:
> Hi,
>
> My OpenJPA app inserts the entity correctly the 1st time, but when it's
> updated, it tries to insert it again causing a data integrity exception. See
> the exception message below. I'm using em.merge() to do the update (as well
> as the initial add). The entity key does not change between the add and
> update.
>
> Can anyone offer some suggestions as to what would cause a situation like
> this? Anyone else run across this? How did you fix it?
>
> I'm using OpenJPA 1.0.1 with Derby 10.2.2.0 and Spring's JPA support (2.0.7)
>
> ROOT CAUSE EXCEPTION MESSAGE
> ----------------------------
> Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: The statement
> was aborted because it would have caused a duplicate key value in a unique or
> primary key constraint or unique index identified by 'SQL071203083750550'
> defined on 'CRUNCHERINFO'. {prepstmnt 18605439 INSERT INTO CruncherInfo
> (serviceURL, accessKey, adminUrl, agentId, commonName, lastRegistration,
> osname, SERVICE_VALUE, state, stateKey, CRUNCHERSTATUS_VALUE) VALUES
> (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [params=(String)
> http://dellberry.cliftonfarm.net:7302, (String) bogus-accesskey, (String)
> http://dellberry.cliftonfarm.net:6322, (String) dellberry.cliftonfarm.net,
> (String) TestName_1, (Timestamp) 2008-01-25 21:02:09.512, (String) Linux,
> (String) TESTTYPE, (String) STOPPED, (String) cruncher.state.stopped,
> (String) DEAUTHORIZED]} [code=20000, state=23505]
>
> ----------------------------
> BTW: SQL071203083750550 is:
>
> ALTER TABLE "APP"."CRUNCHERINFO" ADD CONSTRAINT "SQL071203083750550" PRIMARY
> KEY ("SERVICEURL");
>



-- 
Patrick Linskey
202 669 5907