db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dennis Vredeveld" <vredev...@imst.de>
Subject convenience methods to handle foreign keys not working
Date Mon, 30 Jan 2006 14:20:21 GMT
Hello,

I'm having some troubles with foreign keys when inserting new objects into
an existing DB.
The Torque documentation states that the following should be the most
convenient way to handle foreign keys:

Publisher addison = new Publisher();
addison.setName("Addison Wesley Professional");
addison.save();

/*
 * Using the convenience methods to handle
 * the foreign keys.
 */
Book effective = new Book();
effective.setTitle("Effective Java");
effective.setISBN("0-618-12902-2");
effective.setPublisher(addison);
effective.save();

I'm trying to do the same with a Segment table which as been defined as
follows:
 <table name="Segment">
        <column name="segment_ID" primaryKey="true" required="true"
type="BIGINT"/>
        <column default="NONE" name="IP_Address" required="true"
            size="100" type="VARCHAR"/>
        <column default="0" name="Port" required="true" type="SMALLINT"/>
        <column default="NONE" name="Name" required="true" size="30"
type="VARCHAR"/>
        <column default="0" name="PAN_Identifier" required="true"
type="INTEGER"/>
  </table>

I create and save it using:

// Add Segment
Segment seg = new Segment();
assertNotNull(seg);
seg.setIpAddress(IPAddress1);
seg.setPort(port1);
seg.setName(segment1Name);
try {
     seg.save();
} catch (Exception ex) {
     ex.printStackTrace();
}

The problem is, that the value of segment_ID is 0 at all times. However, in
my opinion it should be updated after the seg.save() statement. When I look
in the database, the Segment instance is correctly stored, but its ID is 1
(the ID is a primary key with auto-increment, so on an emtpy DB, ID=1 is ok
for the first row).
Due to this problem, I cannot use the statement
setSegment(seg) or
setSegmentID(seg.getSegmentId())
on any tables that have foreign keys to Segment, as this yields an SQL error
on a foreign key constraint failing, when trying to insert.

As this belongs to the basic functionality of Torque, I must have been
overlooking something!?

I'm using Torque3.2 on an MySQL DB.


Thanks in advance,
Dennis Vredeveld


---------------------------------------------------------------------
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