-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi,
what do you use as idMethod? It looks to me as if you are using the default "none" which leaves it to you to determine the ids. But since you state that the db creates a correct id you should use idMethod="native" in your table definition. Have a look at http://db.apache.org/torque/generator/schema-reference.html in the databse section. There is some documentation for the attribute [default]idMethod. Patrick Dennis Vredeveld schrieb: > 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFD3ikN8WXLwOuqqQ0RAk4tAKDPZP/3sq+RNboTw/dKNwekAS2/wACfYA+I U+3r8jonLzHGQv9OfHpiO1g= =QB8S -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
