You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Christopher Schmidt <fa...@googlemail.com> on 2010/06/03 21:17:49 UTC

relation "mySequence" already exists

Hi all, using OpenJPA 2.0.0 with Postgresql 8.4 JDBC4

I want to create the schema with the following property:
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(SchemaAction='drop,add')"/>

The entity is defined as follows:

@Entity
@Table(name = "obj_item")
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "obj_item_id_seq", sequenceName =
"obj_item_id_seq", allocationSize = 1)
class ObjectItem ...

it seems that the sequence will not be dropped - so I get the
following exception:
org.apache.openjpa.persistence.PersistenceException: ERROR: relation
"obj_item_id_seq" already exists {stmnt 1834517285 CREATE SEQUENCE
obj_item_id_seq START WITH 1} [code=0, state=42P07]
	at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)...

I found a bug here: https://issues.apache.org/jira/browse/OPENJPA-1259

Any advice?

Regards Christopher

Re: openjpa 2.0 and InverseManager=true

Posted by Michael Dick <mi...@gmail.com>.
Hi Andy,

Are A, B, and C in the same class hierarchy? Did you re-enhance your
entities with 2.0.0 (happens automatically with -javaagent)?

Seems like the field index is off somehow - leading to the wrong inverse
being 'managed'..

-mike

On Thu, Jun 3, 2010 at 3:49 PM, Andrew Thompson <at...@columbia.edu> wrote:

> Hey Folks,
>
> I'm running into an issue upgrading from openjpa 1.2.2 to 2.0 when using
> the inverseManager.
>
> The usecase is:
>
> object A has a lazy bidirectional relationship to object B and A also
> has a lazy bidirectional relationship to object C.  These are
> bidirectional only because it was required to be that way by the jpa 1.0
> spec.  we (unfortunately) depended on the inversemanager to deal
> managing the inverse.
>
> what seems to be happening is:
> an update to object B without properly managing the inverse object A
> sets object C's foreign key relationship to to object A to null.  which
> orphans it.
>
> if possible, i'm looking for the minimal amount of code change.  ie,
> disabling the inversemanager and either updating the relationships to be
> uni directional, or else properly managing inverses fixes the problem.
> similarly having an actual foreign key where it should be means that at
> least data isn't lost.  it's just more labor then i was hoping to
> allocate currently - especially when i haven't heard many other users
> running into issues upgrading.
>
> thanks,
> -Andy
>
>
>

openjpa 2.0 and InverseManager=true

Posted by Andrew Thompson <at...@columbia.edu>.
Hey Folks,

I'm running into an issue upgrading from openjpa 1.2.2 to 2.0 when using
the inverseManager.

The usecase is:

object A has a lazy bidirectional relationship to object B and A also
has a lazy bidirectional relationship to object C.  These are
bidirectional only because it was required to be that way by the jpa 1.0
spec.  we (unfortunately) depended on the inversemanager to deal
managing the inverse.

what seems to be happening is:
an update to object B without properly managing the inverse object A
sets object C's foreign key relationship to to object A to null.  which
orphans it.

if possible, i'm looking for the minimal amount of code change.  ie,
disabling the inversemanager and either updating the relationships to be
uni directional, or else properly managing inverses fixes the problem.
similarly having an actual foreign key where it should be means that at
least data isn't lost.  it's just more labor then i was hoping to
allocate currently - especially when i haven't heard many other users
running into issues upgrading.

thanks,
-Andy



Re: relation "mySequence" already exists

Posted by Jeremy Bauer <te...@gmail.com>.
I agree.  Fixing this would be a good thing, provided it can be fixed
without causing other issues  (ie. removing or attempting to remove other
system created sequences).  I created OPENJPA-1689[1] for this issue.

-Jeremy

[1] https://issues.apache.org/jira/browse/OPENJPA-1689

On Wed, Jun 9, 2010 at 5:50 AM, No1UNo <je...@jerrycarter.org> wrote:

>
> It would be nice to fix this. I'd hate to see anyone else hit this.
> Failing that documenting this unexpected behavior would be okay.
>
> -=- Jerry (via iPhone)
>
> On Jun 9, 2010, at 12:38 AM, "Christopher Schmidt-4 [via OpenJPA]" <
> ml-node+5156733-944799821-93721@n2.nabble.com<ml...@n2.nabble.com>
>  > wrote:
>
> > Jersey,
> >
> > You are right. I changed the sequenceName to xxx and it works...
> >
> > Thx for help :)
> >
> > Am 08.06.2010 23:17 schrieb "Jeremy Bauer" <[hidden email]>:
> >
> > Hi Christopher,
> >
> > As it turns out, I don't think this problem is the same as
> > OPENJPA-1259.
> > There is special code in the PostgresDictionary that treats sequences
> > suffixed with "_SEQ" as system managed sequences.  The comment in
> > PostgresDictionary.isSystemSequence reads:
> >
> >        // filter out generated sequences used for bigserial cols,
> > which are
> >        // of the form <table>_<col>_seq
> >
> > This explains why the same code worked for me on DB2.  Are you able to
> > modify the sequence name?  (ex. sequenceName = "seq_obj_item_id")
> > If not,
> > please file a new JIRA.   It may/should be possible to make the code
> > a bit
> > smarter by actually verifying _seq suffixed sequences are for a
> > bigserial
> > column[1] instead of just making the assumption.
> >
> > -Jeremy
> >
> > [1]
> >
> http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL
> >
> >
> > On Mon, Jun 7, 2010 at 2:39 PM, Jeremy Bauer <[hidden email]> wrote:
> >
> > > Christopher,
> > >
> > > I am ...
> >
> >
> > View message @
> http://openjpa.208410.n2.nabble.com/relation-mySequence-already-exists-tp5136569p5156733.html
> > To start a new topic under OpenJPA Users, email
> ml-node+208411-1595610943-93721@n2.nabble.com<ml...@n2.nabble.com>
> > To unsubscribe from OpenJPA Users, click here.
> >
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/relation-mySequence-already-exists-tp5136569p5157786.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: relation "mySequence" already exists

Posted by No1UNo <je...@jerrycarter.org>.
It would be nice to fix this. I'd hate to see anyone else hit this.  
Failing that documenting this unexpected behavior would be okay.

-=- Jerry (via iPhone)

On Jun 9, 2010, at 12:38 AM, "Christopher Schmidt-4 [via OpenJPA]" <ml-node+5156733-944799821-93721@n2.nabble.com 
 > wrote:

> Jersey,
>
> You are right. I changed the sequenceName to xxx and it works...
>
> Thx for help :)
>
> Am 08.06.2010 23:17 schrieb "Jeremy Bauer" <[hidden email]>:
>
> Hi Christopher,
>
> As it turns out, I don't think this problem is the same as  
> OPENJPA-1259.
> There is special code in the PostgresDictionary that treats sequences
> suffixed with "_SEQ" as system managed sequences.  The comment in
> PostgresDictionary.isSystemSequence reads:
>
>        // filter out generated sequences used for bigserial cols,  
> which are
>        // of the form <table>_<col>_seq
>
> This explains why the same code worked for me on DB2.  Are you able to
> modify the sequence name?  (ex. sequenceName = "seq_obj_item_id")   
> If not,
> please file a new JIRA.   It may/should be possible to make the code  
> a bit
> smarter by actually verifying _seq suffixed sequences are for a  
> bigserial
> column[1] instead of just making the assumption.
>
> -Jeremy
>
> [1]
> http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL
>
>
> On Mon, Jun 7, 2010 at 2:39 PM, Jeremy Bauer <[hidden email]> wrote:
>
> > Christopher,
> >
> > I am ...
>
>
> View message @ http://openjpa.208410.n2.nabble.com/relation-mySequence-already-exists-tp5136569p5156733.html
> To start a new topic under OpenJPA Users, email ml-node+208411-1595610943-93721@n2.nabble.com
> To unsubscribe from OpenJPA Users, click here.
>

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/relation-mySequence-already-exists-tp5136569p5157786.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: relation "mySequence" already exists

Posted by Christopher Schmidt <fa...@googlemail.com>.
Jersey,

You are right. I changed the sequenceName to xxx and it works...

Thx for help :)

Am 08.06.2010 23:17 schrieb "Jeremy Bauer" <te...@gmail.com>:

Hi Christopher,

As it turns out, I don't think this problem is the same as OPENJPA-1259.
There is special code in the PostgresDictionary that treats sequences
suffixed with "_SEQ" as system managed sequences.  The comment in
PostgresDictionary.isSystemSequence reads:

       // filter out generated sequences used for bigserial cols, which are
       // of the form <table>_<col>_seq

This explains why the same code worked for me on DB2.  Are you able to
modify the sequence name?  (ex. sequenceName = "seq_obj_item_id")  If not,
please file a new JIRA.   It may/should be possible to make the code a bit
smarter by actually verifying _seq suffixed sequences are for a bigserial
column[1] instead of just making the assumption.

-Jeremy

[1]
http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL


On Mon, Jun 7, 2010 at 2:39 PM, Jeremy Bauer <te...@gmail.com> wrote:

> Christopher,
>
> I am ...

Re: relation "mySequence" already exists

Posted by Jeremy Bauer <te...@gmail.com>.
Hi Christopher,

As it turns out, I don't think this problem is the same as OPENJPA-1259.
There is special code in the PostgresDictionary that treats sequences
suffixed with "_SEQ" as system managed sequences.  The comment in
PostgresDictionary.isSystemSequence reads:

        // filter out generated sequences used for bigserial cols, which are
        // of the form <table>_<col>_seq

This explains why the same code worked for me on DB2.  Are you able to
modify the sequence name?  (ex. sequenceName = "seq_obj_item_id")  If not,
please file a new JIRA.   It may/should be possible to make the code a bit
smarter by actually verifying _seq suffixed sequences are for a bigserial
column[1] instead of just making the assumption.

-Jeremy

[1]
http://www.postgresql.org/docs/8.4/static/datatype-numeric.html#DATATYPE-SERIAL

On Mon, Jun 7, 2010 at 2:39 PM, Jeremy Bauer <te...@gmail.com> wrote:

> Christopher,
>
> I am able to reproduce the problem now with PostgreSQL using your code
> snippet. For now, I think I should be able to get by without the original
> code.  Thanks so much for the offer, though.  If you could test the fix
> if/when it is ready, that would be a great.
>
> -Jeremy
>
>
> On Mon, Jun 7, 2010 at 1:51 PM, Christopher Schmidt <
> fakod666@googlemail.com> wrote:
>
>> Hi Jeremy, thx for your answer...
>>
>> If it helps I can push the sources and tests to Github (in a view days)?
>>
>> On Mon, Jun 7, 2010 at 8:33 PM, Jeremy Bauer <te...@gmail.com> wrote:
>> > Hi Christopher,
>> >
>> > . . .
>>
>
>

Re: relation "mySequence" already exists

Posted by Jeremy Bauer <te...@gmail.com>.
Christopher,

I am able to reproduce the problem now with PostgreSQL using your code
snippet. For now, I think I should be able to get by without the original
code.  Thanks so much for the offer, though.  If you could test the fix
if/when it is ready, that would be a great.

-Jeremy

On Mon, Jun 7, 2010 at 1:51 PM, Christopher Schmidt <fakod666@googlemail.com
> wrote:

> Hi Jeremy, thx for your answer...
>
> If it helps I can push the sources and tests to Github (in a view days)?
>
> On Mon, Jun 7, 2010 at 8:33 PM, Jeremy Bauer <te...@gmail.com> wrote:
> > Hi Christopher,
> >
> > . . .
>

Re: relation "mySequence" already exists

Posted by Christopher Schmidt <fa...@googlemail.com>.
Hi Jeremy, thx for your answer...

If it helps I can push the sources and tests to Github (in a view days)?

On Mon, Jun 7, 2010 at 8:33 PM, Jeremy Bauer <te...@gmail.com> wrote:
> Hi Christopher,
>
> . . .

Re: relation "mySequence" already exists

Posted by Jeremy Bauer <te...@gmail.com>.
Hi Christopher,

As you found, it looks like you are running into issue OPENJPA-1259.  This
problem appears to be PostgreSQL specific, since I wasn't able to reproduce
the problem on DB2 (the sequence got dropped with DB2).

Not the best solution in the world but, for now, you could specify to ignore
the error.  This allows creation of the remaining DB artifacts to continue
and permits the app to run.

<property name="openjpa.jdbc.SynchronizeMappings"

value="buildSchema(SchemaAction='drop,add',IgnoreErrors=true)"/>

Unless someone else tackles it first, I should have some time to look into
the issue later this week.

hth,
-Jeremy

On Thu, Jun 3, 2010 at 2:17 PM, Christopher Schmidt <fakod666@googlemail.com
> wrote:

> Hi all, using OpenJPA 2.0.0 with Postgresql 8.4 JDBC4
>
> I want to create the schema with the following property:
> <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(SchemaAction='drop,add')"/>
>
> The entity is defined as follows:
>
> @Entity
> @Table(name = "obj_item")
> @Inheritance(strategy = InheritanceType.JOINED)
> @SequenceGenerator(name = "obj_item_id_seq", sequenceName =
> "obj_item_id_seq", allocationSize = 1)
> class ObjectItem ...
>
> it seems that the sequence will not be dropped - so I get the
> following exception:
> org.apache.openjpa.persistence.PersistenceException: ERROR: relation
> "obj_item_id_seq" already exists {stmnt 1834517285 CREATE SEQUENCE
> obj_item_id_seq START WITH 1} [code=0, state=42P07]
>        at
> org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)...
>
> I found a bug here: https://issues.apache.org/jira/browse/OPENJPA-1259
>
> Any advice?
>
> Regards Christopher
>

Fwd: relation "mySequence" already exists

Posted by Christopher Schmidt <fa...@googlemail.com>.
Hi, do you have any advice?


---------- Forwarded message ----------
From: Christopher Schmidt <fa...@googlemail.com>
Date: Thu, Jun 3, 2010 at 9:17 PM
Subject: relation "mySequence" already exists
To: users@openjpa.apache.org


Hi all, using OpenJPA 2.0.0 with Postgresql 8.4 JDBC4

I want to create the schema with the following property:
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(SchemaAction='drop,add')"/>

The entity is defined as follows:

@Entity
@Table(name = "obj_item")
@Inheritance(strategy = InheritanceType.JOINED)
@SequenceGenerator(name = "obj_item_id_seq", sequenceName =
"obj_item_id_seq", allocationSize = 1)
class ObjectItem ...

it seems that the sequence will not be dropped - so I get the
following exception:
org.apache.openjpa.persistence.PersistenceException: ERROR: relation
"obj_item_id_seq" already exists {stmnt 1834517285 CREATE SEQUENCE
obj_item_id_seq START WITH 1} [code=0, state=42P07]
       at org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:556)...

I found a bug here: https://issues.apache.org/jira/browse/OPENJPA-1259

Any advice?

Regards Christopher