pg.ddx.io pgsql-jdbc@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Transaction foreign key violation 2+ messages / 2 participants [nested] [flat]
* Transaction foreign key violation @ 2006-05-04 13:13 Martina <boehme@mpiib-berlin.mpg.de> 2006-05-04 16:35 ` Re: Transaction foreign key violation Oliver Jowett <oliver@opencloud.com> 0 siblings, 1 reply; 2+ messages in thread From: Martina @ 2006-05-04 13:13 UTC (permalink / raw) To: pgsql-jdbc I'm getting a foreign key constraint violation if I run a transaction in which the first statement inserts a new row in Table1 (with serial as pk, "idTable1") and the second statement gets this "idTable1" as a fk. Because it is not there yet (but in the same transaction) I get this error. If I don't use transaction it is working. What can I do? This fk constraint is set DEFERRABLE INITIALLY DEFERRED. I tried "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE" (just with query.execute() before the other statements)) - no luck. If I commit the statements via pgAdmin with BEGIN; INSERT INTO ..; COMMIT; it is working fine. I use 8.1-405 JDBC3 Thanks for suggestions! Martina ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Transaction foreign key violation 2006-05-04 13:13 Transaction foreign key violation Martina <boehme@mpiib-berlin.mpg.de> @ 2006-05-04 16:35 ` Oliver Jowett <oliver@opencloud.com> 0 siblings, 0 replies; 2+ messages in thread From: Oliver Jowett @ 2006-05-04 16:35 UTC (permalink / raw) To: Martina <boehme@mpiib-berlin.mpg.de>; +Cc: pgsql-jdbc Martina wrote: > > I'm getting a foreign key constraint violation if I run a transaction in > which the first statement inserts a new row in Table1 (with serial as > pk, "idTable1") and the second statement gets this "idTable1" as a fk. > Because it is not there yet (but in the same transaction) I get this > error. If I don't use transaction it is working. > What can I do? Can you show us your code, or (better) a small testcase that shows the problem? > I tried "SET > TRANSACTION ISOLATION LEVEL SERIALIZABLE" (just with query.execute() > before the other statements)) - no luck. The right way to do this is via Connection.setTransactionIsolation(). -O ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-05-04 16:35 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2006-05-04 13:13 Transaction foreign key violation Martina <boehme@mpiib-berlin.mpg.de> 2006-05-04 16:35 ` Oliver Jowett <oliver@opencloud.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox