You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Shevek <sh...@anarres.org> on 2004/04/22 03:38:52 UTC

Yet Another Sequence Bug in Postgres

If you insert a row into a postgres table with an explicitly specified
primary id, it also tries to call currval on a sequence which has never
been used.

BasePeer should check whether an auto_incrementing primary was explicitly
specified before trying to get it from a sequence which hasn't been used.

The business case for doing this is that it's the only way to create a
hierarchical structure: Since postgres enforces referential integrity
constraints on null foreign keys, one must insert a row with known primary
and self-referential foreign key, i.e. use an explicit primary.

	Criteria criteria = new Criteria();
	criteria.add(FooPeer.ID, id);
	criteria.add(FooPeer.PARENTID, id);
	HClassClassPeer.doInsert(criteria);

Removing the 'create sequence' code from the postgres velocity templates
seems to fix the earlier 'Cannot insert into postgres' bug. But on the
basis that it requires a fix in torque to work with 7.3, I still believe
that that earlier bug is outstanding in torque 3.1.

Torque seems to be unable to cope with self referential constraints in any 
way at all. It didn't generate any bean code for them either.

S.

-- 
Shevek                                    http://www.anarres.org/
I am the Borg.                         http://www.gothnicity.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Re: Yet Another Sequence Bug in Postgres

Posted by Scott Eade <se...@backstagetech.com.au>.
Shevek wrote:

>If you insert a row into a postgres table with an explicitly specified
>primary id, it also tries to call currval on a sequence which has never
>been used.
>
>BasePeer should check whether an auto_incrementing primary was explicitly
>specified before trying to get it from a sequence which hasn't been used.
>
>The business case for doing this is that it's the only way to create a
>hierarchical structure: Since postgres enforces referential integrity
>constraints on null foreign keys, one must insert a row with known primary
>and self-referential foreign key, i.e. use an explicit primary.
>
>	Criteria criteria = new Criteria();
>	criteria.add(FooPeer.ID, id);
>	criteria.add(FooPeer.PARENTID, id);
>	HClassClassPeer.doInsert(criteria);
>
>Removing the 'create sequence' code from the postgres velocity templates
>seems to fix the earlier 'Cannot insert into postgres' bug. But on the
>basis that it requires a fix in torque to work with 7.3, I still believe
>that that earlier bug is outstanding in torque 3.1.
>
>Torque seems to be unable to cope with self referential constraints in any 
>way at all. It didn't generate any bean code for them either.
>  
>
I suggest you add this and your other issue to the PostgreSQL FAQ so 
that others can be informed about them.

As to fixing them, it is a matter of which itch a developer wants to 
scratch.  Your patches would be most welcome.

Scott

-- 
Scott Eade
Backstage Technologies Pty. Ltd.
http://www.backstagetech.com.au


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org