db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henrik Vendelbo" <hvende...@bluprints.com>
Subject Re: simple reference problem
Date Wed, 04 Feb 2004 19:36:56 GMT
As far as I can tell what happens is the following :

I create a new consumer instance and then a record. As default the primary
key of consumer is = 0
I then fill in the values and save() the new consumer

I then create a handset instance and a record. As default the primary key of
handset is = 0
I point handset to the consumer
I then fill in the values and save() the new handset

Looking over the code of BaseConsumerPeer, it apparently leaves the consumer
object alone during save, leaving the primary key = 0
So when I try to refer to the object, it actually represents an invalid (and
nonexistent) record.

Either this is a bug, or I need to assign the primary key after save, which
I am currently looking into

Henrik

P.S. The stack trace is not terribly informative I am affraid.


java.sql.SQLException: General error,  message from server: "Cannot add or
update a child row: a foreign key constraint fails"
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
 at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1680)
 at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1527)
 at com.workingdogs.village.Record.saveWithInsert(Unknown Source)
 at com.workingdogs.village.Record.save(Unknown Source)
 at com.workingdogs.village.Record.save(Unknown Source)
 at org.apache.torque.util.BasePeer.insertOrUpdateRecord(BasePeer.java:899)
 at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:742)
 at
com.bluprints.mobile.db.model.BaseConsumerHandsetPeer.doInsert(BaseConsumerH
andsetPeer.java:222)
 at
com.bluprints.mobile.db.model.BaseConsumerHandsetPeer.doInsert(BaseConsumerH
andsetPeer.java:572)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1996)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1960)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1940)
 at
com.bluprints.mobile.db.test.PhoneCommandTestCase.setUp(PhoneCommandTestCase
.java:56)
 at junit.framework.TestCase.runBare(TestCase.java:125)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.framework.TestSuite.runTest(TestSuite.java:208)
 at junit.framework.TestSuite.run(TestSuite.java:203)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:397)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
java:281)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
.java:173)
rethrown as org.apache.torque.TorqueException: General error,  message from
server: "Cannot add or update a child row: a foreign key constraint fails"
 at org.apache.torque.util.BasePeer.throwTorqueException(BasePeer.java:236)
 at org.apache.torque.util.BasePeer.insertOrUpdateRecord(BasePeer.java:903)
 at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:742)
 at
com.bluprints.mobile.db.model.BaseConsumerHandsetPeer.doInsert(BaseConsumerH
andsetPeer.java:222)
 at
com.bluprints.mobile.db.model.BaseConsumerHandsetPeer.doInsert(BaseConsumerH
andsetPeer.java:572)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1996)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1960)
 at
com.bluprints.mobile.db.model.BaseConsumerHandset.save(BaseConsumerHandset.j
ava:1940)
 at
com.bluprints.mobile.db.test.PhoneCommandTestCase.setUp(PhoneCommandTestCase
.java:56)
 at junit.framework.TestCase.runBare(TestCase.java:125)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.framework.TestSuite.runTest(TestSuite.java:208)
 at junit.framework.TestSuite.run(TestSuite.java:203)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:397)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
java:281)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
.java:173)
Caused by: java.sql.SQLException: General error,  message from server:
"Cannot add or update a child row: a foreign key constraint fails"
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1876)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1098)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1192)
 at com.mysql.jdbc.Connection.execSQL(Connection.java:2051)
 at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1680)
 at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1527)
 at com.workingdogs.village.Record.saveWithInsert(Unknown Source)
 at com.workingdogs.village.Record.save(Unknown Source)
 at com.workingdogs.village.Record.save(Unknown Source)
 at org.apache.torque.util.BasePeer.insertOrUpdateRecord(BasePeer.java:899)
 ... 17 more


----- Original Message ----- 
From: "Andres Quijano - Rizonet" <andres@rizo.net>
To: "'Apache Torque Users List'" <torque-user@db.apache.org>
Sent: Wednesday, February 04, 2004 7:13 PM
Subject: RE: simple reference problem


Tell us why it failed. Post some stacktrace or log or something

-----Original Message-----
From: Henrik Vendelbo [mailto:hvendelbo@bluprints.com]
Sent: MiƩrcoles, 04 de Febrero de 2004 04:09 p.m.
To: Apache Torque Users List
Subject: Re: simple reference problem


that fails, yet setting the consumerid to the value of 1 and then
inserting works just fine.

I thought that the primary key was automatically updated on a
save/insert, is that not so ?

consumer = new Consumer();

consumer.setFirstName("John");

consumer.setSurname("Doe");

consumer.setHouseNo("25");

consumer.setBirthdate(new Date("01/01/1970"));

consumer.setLanguage((byte)1);

consumer.setCreated(new Date());

consumer.save();


handset.setConsumer(consumer) ;

//handset.setConsumerid(1);

handset.setPhoneNo("00447930416886");

handset.setPhoneManufacturer(1);

handset.setPhoneModel(1);

handset.save();

(code above failed)



----- Original Message ----- 
From: "Andres Quijano - Rizonet" <andres@rizo.net>
To: "'Apache Torque Users List'" <torque-user@db.apache.org>
Sent: Wednesday, February 04, 2004 6:35 PM
Subject: RE: simple reference problem


try

handset.save()

-----Original Message-----
From: Henrik Vendelbo [mailto:hvendelbo@bluprints.com]
Sent: MiƩrcoles, 04 de Febrero de 2004 03:34 p.m.
To: Apache Torque Users List
Subject: simple reference problem


On two related tables I try to insert new records. On handset there is a
foreign key enforcing 'consumerid' to refer to a consumer. I have tried
using handset.setConsumerid() and handset.setConsumer(). In either case
it fails on the foreign key constraint.

What might be the problem ?
consumer = new Consumer();

consumer.setFirstName("John");

consumer.setSurname("Doe");

consumer.setHouseNo("25");

consumer.setBirthdate(new Date("01/01/1970"));

consumer.setLanguage((byte)1);

consumer.setCreated(new Date());

consumer.save();


handset.setConsumer(consumer) ;

handset.setPhoneNo("0044416886");

handset.setPhoneManufacturer(1);

handset.setPhoneModel(1);

ConsumerHandsetPeer.doInsert(handset);



Cheers,

Henrik



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




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






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



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





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


Mime
View raw message