You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Jens Mayer <je...@gmx.de> on 2007/04/06 18:53:10 UTC

Newbie Question concerning pk autoincrementing

Hi,

I'm using cayenne with oracle 9.2.0.3.0
The pk-attributes in my schema are automatically generated by 
before-insert-triggers, so cayenne doesn't have to bother generating any 
   pk. Due to this, I set the PK Generation Strategy for all DbEntities 
to "Database-Generated".
And here comes the problem: everytime cayenne is doing an insert, a 
"select pk_xyz.nextval from dual" is fired. What's that ? Did I 
missunderstood anything ? I expected cayenne to ignore the pk-attributes 
completely.

Any help appreciated.

Greets Jens

Re: Newbie Question concerning pk autoincrementing

Posted by Michael Gentry <bl...@gmail.com>.
Also, this isn't a Cayenne-specific problem, either.  I'd so most, if not
all, ORM technologies would have an issue with the DB generating PKs behind
the scenes without the ORM stack knowing the values that were assigned.

Thanks,

/dev/mrg


On 4/6/07, Andrus Adamchik <an...@objectstyle.org> wrote:
>
>
> On Apr 6, 2007, at 12:53 PM, Jens Mayer wrote:
>
> > I'm using cayenne with oracle 9.2.0.3.0
> > The pk-attributes in my schema are automatically generated by
> > before-insert-triggers, so cayenne doesn't have to bother
> > generating any   pk. Due to this, I set the PK Generation Strategy
> > for all DbEntities to "Database-Generated".
> > And here comes the problem: everytime cayenne is doing an insert, a
> > "select pk_xyz.nextval from dual" is fired. What's that ? Did I
> > missunderstood anything ? I expected cayenne to ignore the pk-
> > attributes completely.
>
> Essentially when Cayenne knows (ok "assumes" is a more proper word)
> that db-generated pk doesn't work, it fires its own PK generator. The
> problem with using a trigger for PK is that there is no way to pass
> back that value to Cayenne via JDBC, hence Cayenne can't
> appropriately handle newly inserted object after commit. This is a
> JDBC limitation, and I am not aware of a workaround for it on the
> Java end.
>
> Andrus
>
>
>
>

Re: Newbie Question concerning pk autoincrementing

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Apr 6, 2007, at 12:53 PM, Jens Mayer wrote:

> I'm using cayenne with oracle 9.2.0.3.0
> The pk-attributes in my schema are automatically generated by  
> before-insert-triggers, so cayenne doesn't have to bother  
> generating any   pk. Due to this, I set the PK Generation Strategy  
> for all DbEntities to "Database-Generated".
> And here comes the problem: everytime cayenne is doing an insert, a  
> "select pk_xyz.nextval from dual" is fired. What's that ? Did I  
> missunderstood anything ? I expected cayenne to ignore the pk- 
> attributes completely.

Essentially when Cayenne knows (ok "assumes" is a more proper word)  
that db-generated pk doesn't work, it fires its own PK generator. The  
problem with using a trigger for PK is that there is no way to pass  
back that value to Cayenne via JDBC, hence Cayenne can't  
appropriately handle newly inserted object after commit. This is a  
JDBC limitation, and I am not aware of a workaround for it on the  
Java end.

Andrus