You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Hans J. Prueller" <ha...@gmx.net> on 2007/02/10 18:23:51 UTC
Using @GeneratedValue for IDs on already existing tables
As some of you may remember, I am using OpenJPA within an "old" Java2EE
1.4/EJB2.1 container to perform
a step-by-step or bean-by-bean migration from our EJB2.1 CMP entity beans to
new EJB3 Beans with JPA.
For the IDs of the Entity Beans we have been using a
Container-Generated-Value and I plan to continue doing
so by using the JPA's @GeneratedValue stuff.
Are there any special issues to consider when using the new openJPA based
entities with generated values
on already existing data? In special I mean conflicts of between openJPA
generated IDs with existing IDs in
the underlying table?
Hans
AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by "Hans J. Prueller" <ha...@gmx.net>.
Patrick,
> It would certainly be possible to implement such a thing in OpenJPA, but
> there is no such feature in place currently.
perhaps this would be a nice feature for the future - if I'll find another
working solution that avoids the case of generating an already existing PK
I don't need it.
> If you're decommissioning the old system, one easy way to make things work
> would be to use a hi-lo table with per-class entries (the class-table
> alias), and then manually configure the start value in the table (using
> the main() method in the org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq)
> to be the highest existing PK value for each table.
this sounds good - thank you for the tip.
regards,
HANS
> -----Ursprüngliche Nachricht-----
> Von: Patrick Linskey [mailto:plinskey@bea.com]
> Gesendet: Dienstag, 13. Februar 2007 18:13
> An: open-jpa-dev@incubator.apache.org
> Betreff: RE: AW: Using @GeneratedValue for IDs on already existing tables
>
> > I can remember a legacy persistence framework that was able to retry
> > the insert statement with a "second-try generated PK" just
> > for the case
> > the currently generated one has already been inserted by
> > another process.
>
> It would certainly be possible to implement such a thing in OpenJPA, but
> there is no such feature in place currently.
>
> If you're decommissioning the old system, one easy way to make things work
> would be to use a hi-lo table with per-class entries (the class-table
> alias), and then manually configure the start value in the table (using
> the main() method in the org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq)
> to be the highest existing PK value for each table.
>
> -Patrick
>
> --
> Patrick Linskey
> BEA Systems, Inc.
>
> _______________________________________________________________________
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>
> > -----Original Message-----
> > From: Hans J. Prueller [mailto:hans.prueller@gmx.net]
> > Sent: Tuesday, February 13, 2007 9:01 AM
> > To: open-jpa-dev@incubator.apache.org
> > Subject: AW: AW: Using @GeneratedValue for IDs on already
> > existing tables
> >
> > thanks for this link but this section only describes the different
> > algorithms that are provided to get the generated value - it does
> > not mention the case what happens if we try to save a new persistent
> > entity with a generated PK value that already exists in the DB?
> >
> > I can remember a legacy persistence framework that was able to retry
> > the insert statement with a "second-try generated PK" just
> > for the case
> > the currently generated one has already been inserted by
> > another process.
> >
> > does nobody else have a similar requirement?
> >
> > hans
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Abe White [mailto:awhite@bea.com]
> > > Gesendet: Dienstag, 13. Februar 2007 17:35
> > > An: open-jpa-dev@incubator.apache.org
> > > Betreff: Re: AW: Using @GeneratedValue for IDs on already
> > existing tables
> > >
> > > > does openJPA provide the strategy to re-generate another value for
> > > > the PK
> > > > or do we have to manually deal with this case?
> > >
> > > http://incubator.apache.org/openjpa/docs/latest/manual/
> > > manual.html#ref_guide_sequence
> > >
> > ______________________________________________________________
> > _________
> > > Notice: This email message, together with any attachments,
> > may contain
> > > information of BEA Systems, Inc., its subsidiaries and
> > affiliated
> > > entities, that may be confidential, proprietary,
> > copyrighted and/or
> > > legally privileged, and is intended solely for the use of
> > the individual
> > > or entity named in this message. If you are not the
> > intended recipient,
> > > and have received this message in error, please immediately
> > return this
> > > by email and then delete it.
> >
> >
RE: AW: Using @GeneratedValue for IDs on already existing tables
Posted by Patrick Linskey <pl...@bea.com>.
> I can remember a legacy persistence framework that was able to retry
> the insert statement with a "second-try generated PK" just
> for the case
> the currently generated one has already been inserted by
> another process.
It would certainly be possible to implement such a thing in OpenJPA, but there is no such feature in place currently.
If you're decommissioning the old system, one easy way to make things work would be to use a hi-lo table with per-class entries (the class-table alias), and then manually configure the start value in the table (using the main() method in the org.apache.openjpa.jdbc.kernel.ClassTableJDBCSeq) to be the highest existing PK value for each table.
-Patrick
--
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
> -----Original Message-----
> From: Hans J. Prueller [mailto:hans.prueller@gmx.net]
> Sent: Tuesday, February 13, 2007 9:01 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: AW: AW: Using @GeneratedValue for IDs on already
> existing tables
>
> thanks for this link but this section only describes the different
> algorithms that are provided to get the generated value - it does
> not mention the case what happens if we try to save a new persistent
> entity with a generated PK value that already exists in the DB?
>
> I can remember a legacy persistence framework that was able to retry
> the insert statement with a "second-try generated PK" just
> for the case
> the currently generated one has already been inserted by
> another process.
>
> does nobody else have a similar requirement?
>
> hans
>
> > -----Ursprüngliche Nachricht-----
> > Von: Abe White [mailto:awhite@bea.com]
> > Gesendet: Dienstag, 13. Februar 2007 17:35
> > An: open-jpa-dev@incubator.apache.org
> > Betreff: Re: AW: Using @GeneratedValue for IDs on already
> existing tables
> >
> > > does openJPA provide the strategy to re-generate another value for
> > > the PK
> > > or do we have to manually deal with this case?
> >
> > http://incubator.apache.org/openjpa/docs/latest/manual/
> > manual.html#ref_guide_sequence
> >
> ______________________________________________________________
> _________
> > Notice: This email message, together with any attachments,
> may contain
> > information of BEA Systems, Inc., its subsidiaries and
> affiliated
> > entities, that may be confidential, proprietary,
> copyrighted and/or
> > legally privileged, and is intended solely for the use of
> the individual
> > or entity named in this message. If you are not the
> intended recipient,
> > and have received this message in error, please immediately
> return this
> > by email and then delete it.
>
>
Re: AW: AW: AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by Dain Sundstrom <da...@iq80.com>.
On Feb 13, 2007, at 2:38 PM, Hans J. Prueller wrote:
> Don't be afraid - it is definitely NOT JBOSS ;-)
>
> Isn't it hibernate behind the scenes of the JBoss CMP engine?
Last time I checked they were still using my ancient cruft :)
> I have been using hibernate for several years now and I'm pretty
> happy with
> it. I'm not sure where all the RedHat/JBoss stuff is going - I assume
> betting on OpenJPA/Geronimo will be a good bet for the future ;-)
Of course... soooooo obvious ;)
-dain
AW: AW: AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by "Hans J. Prueller" <ha...@gmx.net>.
Don't be afraid - it is definitely NOT JBOSS ;-)
Isn't it hibernate behind the scenes of the JBoss CMP engine?
I have been using hibernate for several years now and I'm pretty happy with
it. I'm not sure where all the RedHat/JBoss stuff is going - I assume
betting on OpenJPA/Geronimo will be a good bet for the future ;-)
regards,
Hans
> -----Ursprüngliche Nachricht-----
> Von: Dain Sundstrom [mailto:dain@iq80.com]
> Gesendet: Dienstag, 13. Februar 2007 20:11
> An: open-jpa-dev@incubator.apache.org
> Betreff: Re: AW: AW: AW: Using @GeneratedValue for IDs on already existing
> tables
>
>
> On Feb 13, 2007, at 10:06 AM, Hans J. Prueller wrote:
>
> >> Can you tell us your current J2EE vendor, and if possible the
> >> generation
> >> strategy selected in the vendor deployment descriptor. If not,
> >> can you
> >> grab the last 20 pks from one of the tables, we may be able to
> >> guess the
> >> strategy
> >
> > One of the reasons why we are migrating is that the current vendors
> > generation strategy is crap - we regularly get "duplicate PK" SQL
> > exceptions
> > on our production servers and the vendor developers don't understand
> > that their PK generation algorithm is not "production ready" or
> > stable yet.
> >
> > I don't want to make a product down so I don't name it here but the
> > fact is
> > that we permanently are having stability problems with the CMP engine.
>
>
> If it is JBoss, feel free to diss it as I am the one that wrote that
> CMP engine :)
>
> -dain
Re: AW: AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by Dain Sundstrom <da...@iq80.com>.
On Feb 13, 2007, at 10:06 AM, Hans J. Prueller wrote:
>> Can you tell us your current J2EE vendor, and if possible the
>> generation
>> strategy selected in the vendor deployment descriptor. If not,
>> can you
>> grab the last 20 pks from one of the tables, we may be able to
>> guess the
>> strategy
>
> One of the reasons why we are migrating is that the current vendors
> generation strategy is crap - we regularly get "duplicate PK" SQL
> exceptions
> on our production servers and the vendor developers don't understand
> that their PK generation algorithm is not "production ready" or
> stable yet.
>
> I don't want to make a product down so I don't name it here but the
> fact is
> that we permanently are having stability problems with the CMP engine.
If it is JBoss, feel free to diss it as I am the one that wrote that
CMP engine :)
-dain
AW: AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by "Hans J. Prueller" <ha...@gmx.net>.
> Can you tell us your current J2EE vendor, and if possible the generation
> strategy selected in the vendor deployment descriptor. If not, can you
> grab the last 20 pks from one of the tables, we may be able to guess the
> strategy
One of the reasons why we are migrating is that the current vendors
generation strategy is crap - we regularly get "duplicate PK" SQL exceptions
on our production servers and the vendor developers don't understand
that their PK generation algorithm is not "production ready" or stable yet.
I don't want to make a product down so I don't name it here but the fact is
that we permanently are having stability problems with the CMP engine.
The solution with hi-lo table setting the value to the current max() of the
db values provided by Patrick sounds good - I think I'll give it a try.
thank you!
hans
> -----Ursprüngliche Nachricht-----
> Von: Dain Sundstrom [mailto:dain@iq80.com]
> Gesendet: Dienstag, 13. Februar 2007 18:36
> An: open-jpa-dev@incubator.apache.org
> Betreff: Re: AW: AW: Using @GeneratedValue for IDs on already existing
> tables
>
> Can you tell us your current J2EE vendor, and if possible the
> generation strategy selected in the vendor deployment descriptor. If
> not,
> can you grab the last 20 pks from one of the tables, we may be able
> to guess the strategy.
>
> In general, if you vendor is using a UUID, you should able to use a
> OpenJPA UUID without conflicts. If the vendor is using some sort of
> DB sequence, you should be able to start a new sequence for OpenJPA
> using a much larger starting number.
>
> -dain
>
> On Feb 13, 2007, at 9:00 AM, Hans J. Prueller wrote:
>
> > thanks for this link but this section only describes the different
> > algorithms that are provided to get the generated value - it does
> > not mention the case what happens if we try to save a new persistent
> > entity with a generated PK value that already exists in the DB?
> >
> > I can remember a legacy persistence framework that was able to retry
> > the insert statement with a "second-try generated PK" just for the
> > case
> > the currently generated one has already been inserted by another
> > process.
> >
> > does nobody else have a similar requirement?
> >
> > hans
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Abe White [mailto:awhite@bea.com]
> >> Gesendet: Dienstag, 13. Februar 2007 17:35
> >> An: open-jpa-dev@incubator.apache.org
> >> Betreff: Re: AW: Using @GeneratedValue for IDs on already existing
> >> tables
> >>
> >>> does openJPA provide the strategy to re-generate another value for
> >>> the PK
> >>> or do we have to manually deal with this case?
> >>
> >> http://incubator.apache.org/openjpa/docs/latest/manual/
> >> manual.html#ref_guide_sequence
> >> _____________________________________________________________________
> >> __
> >> Notice: This email message, together with any attachments, may
> >> contain
> >> information of BEA Systems, Inc., its subsidiaries and
> >> affiliated
> >> entities, that may be confidential, proprietary, copyrighted
> >> and/or
> >> legally privileged, and is intended solely for the use of the
> >> individual
> >> or entity named in this message. If you are not the intended
> >> recipient,
> >> and have received this message in error, please immediately return
> >> this
> >> by email and then delete it.
> >
Re: AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by Dain Sundstrom <da...@iq80.com>.
Can you tell us your current J2EE vendor, and if possible the
generation strategy selected in the vendor deployment descriptor. If
not,
can you grab the last 20 pks from one of the tables, we may be able
to guess the strategy.
In general, if you vendor is using a UUID, you should able to use a
OpenJPA UUID without conflicts. If the vendor is using some sort of
DB sequence, you should be able to start a new sequence for OpenJPA
using a much larger starting number.
-dain
On Feb 13, 2007, at 9:00 AM, Hans J. Prueller wrote:
> thanks for this link but this section only describes the different
> algorithms that are provided to get the generated value - it does
> not mention the case what happens if we try to save a new persistent
> entity with a generated PK value that already exists in the DB?
>
> I can remember a legacy persistence framework that was able to retry
> the insert statement with a "second-try generated PK" just for the
> case
> the currently generated one has already been inserted by another
> process.
>
> does nobody else have a similar requirement?
>
> hans
>
>> -----Ursprüngliche Nachricht-----
>> Von: Abe White [mailto:awhite@bea.com]
>> Gesendet: Dienstag, 13. Februar 2007 17:35
>> An: open-jpa-dev@incubator.apache.org
>> Betreff: Re: AW: Using @GeneratedValue for IDs on already existing
>> tables
>>
>>> does openJPA provide the strategy to re-generate another value for
>>> the PK
>>> or do we have to manually deal with this case?
>>
>> http://incubator.apache.org/openjpa/docs/latest/manual/
>> manual.html#ref_guide_sequence
>> _____________________________________________________________________
>> __
>> Notice: This email message, together with any attachments, may
>> contain
>> information of BEA Systems, Inc., its subsidiaries and
>> affiliated
>> entities, that may be confidential, proprietary, copyrighted
>> and/or
>> legally privileged, and is intended solely for the use of the
>> individual
>> or entity named in this message. If you are not the intended
>> recipient,
>> and have received this message in error, please immediately return
>> this
>> by email and then delete it.
>
AW: AW: Using @GeneratedValue for IDs on already existing tables
Posted by "Hans J. Prueller" <ha...@gmx.net>.
thanks for this link but this section only describes the different
algorithms that are provided to get the generated value - it does
not mention the case what happens if we try to save a new persistent
entity with a generated PK value that already exists in the DB?
I can remember a legacy persistence framework that was able to retry
the insert statement with a "second-try generated PK" just for the case
the currently generated one has already been inserted by another process.
does nobody else have a similar requirement?
hans
> -----Ursprüngliche Nachricht-----
> Von: Abe White [mailto:awhite@bea.com]
> Gesendet: Dienstag, 13. Februar 2007 17:35
> An: open-jpa-dev@incubator.apache.org
> Betreff: Re: AW: Using @GeneratedValue for IDs on already existing tables
>
> > does openJPA provide the strategy to re-generate another value for
> > the PK
> > or do we have to manually deal with this case?
>
> http://incubator.apache.org/openjpa/docs/latest/manual/
> manual.html#ref_guide_sequence
> _______________________________________________________________________
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
Re: AW: Using @GeneratedValue for IDs on already existing tables
Posted by Abe White <aw...@bea.com>.
> does openJPA provide the strategy to re-generate another value for
> the PK
> or do we have to manually deal with this case?
http://incubator.apache.org/openjpa/docs/latest/manual/
manual.html#ref_guide_sequence
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
AW: Using @GeneratedValue for IDs on already existing tables
Posted by "Hans J. Prueller" <ha...@gmx.net>.
Patrick,
thank you for your reply. The generation algorithm we are using currently
is provided from our EJB2.1 CMP container and is a blackbox for us.
As we are not very happy with the current solution we are
planning/evaluating the migration of the whole EJB2.1 persistence layer to
OpenJPA/JPA.
What I tried to find out is what happens if we map the new OpenJPA
persistent POJO onto the already existing and populated table (we did that
already, querying works fine) and the add new instances (db rows) using
the JPA @generatedvalue annotation:
a) if the openjpa generated PK value is unique everything will work fine,
but
b) what if the openjpa generated PK value already exists???
does openJPA provide the strategy to re-generate another value for the PK
or do we have to manually deal with this case?
HANS
> -----Ursprüngliche Nachricht-----
> Von: Patrick Linskey [mailto:plinskey@bea.com]
> Gesendet: Dienstag, 13. Februar 2007 06:52
> An: open-jpa-dev@incubator.apache.org
> Betreff: RE: Using @GeneratedValue for IDs on already existing tables
>
> How do you currently generate your values? If you use some sort of
> database-side logic (sequence, auto-assigned columns, hi-lo table), it
> should be trivial for Kodo to interoperate. If you're using some sort of
> fancy in-process algorithm, it may be more difficult, but is certainly
> doable.
>
> -Patrick
>
> --
> Patrick Linskey
> BEA Systems, Inc.
>
> _______________________________________________________________________
> Notice: This email message, together with any attachments, may contain
> information of BEA Systems, Inc., its subsidiaries and affiliated
> entities, that may be confidential, proprietary, copyrighted and/or
> legally privileged, and is intended solely for the use of the individual
> or entity named in this message. If you are not the intended recipient,
> and have received this message in error, please immediately return this
> by email and then delete it.
>
> > -----Original Message-----
> > From: Hans J. Prueller [mailto:hans.prueller@gmx.net]
> > Sent: Saturday, February 10, 2007 9:24 AM
> > To: open-jpa-dev@incubator.apache.org
> > Subject: Using @GeneratedValue for IDs on already existing tables
> >
> > As some of you may remember, I am using OpenJPA within an
> > "old" Java2EE
> > 1.4/EJB2.1 container to perform
> >
> > a step-by-step or bean-by-bean migration from our EJB2.1 CMP
> > entity beans to
> > new EJB3 Beans with JPA.
> >
> >
> >
> > For the IDs of the Entity Beans we have been using a
> > Container-Generated-Value and I plan to continue doing
> >
> > so by using the JPA's @GeneratedValue stuff.
> >
> >
> >
> > Are there any special issues to consider when using the new
> > openJPA based
> > entities with generated values
> >
> > on already existing data? In special I mean conflicts of
> > between openJPA
> > generated IDs with existing IDs in
> >
> > the underlying table?
> >
> >
> >
> > Hans
> >
> >
RE: Using @GeneratedValue for IDs on already existing tables
Posted by Patrick Linskey <pl...@bea.com>.
How do you currently generate your values? If you use some sort of
database-side logic (sequence, auto-assigned columns, hi-lo table), it
should be trivial for Kodo to interoperate. If you're using some sort of
fancy in-process algorithm, it may be more difficult, but is certainly
doable.
-Patrick
--
Patrick Linskey
BEA Systems, Inc.
_______________________________________________________________________
Notice: This email message, together with any attachments, may contain
information of BEA Systems, Inc., its subsidiaries and affiliated
entities, that may be confidential, proprietary, copyrighted and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.
> -----Original Message-----
> From: Hans J. Prueller [mailto:hans.prueller@gmx.net]
> Sent: Saturday, February 10, 2007 9:24 AM
> To: open-jpa-dev@incubator.apache.org
> Subject: Using @GeneratedValue for IDs on already existing tables
>
> As some of you may remember, I am using OpenJPA within an
> "old" Java2EE
> 1.4/EJB2.1 container to perform
>
> a step-by-step or bean-by-bean migration from our EJB2.1 CMP
> entity beans to
> new EJB3 Beans with JPA.
>
>
>
> For the IDs of the Entity Beans we have been using a
> Container-Generated-Value and I plan to continue doing
>
> so by using the JPA's @GeneratedValue stuff.
>
>
>
> Are there any special issues to consider when using the new
> openJPA based
> entities with generated values
>
> on already existing data? In special I mean conflicts of
> between openJPA
> generated IDs with existing IDs in
>
> the underlying table?
>
>
>
> Hans
>
>