db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: convenience methods to handle foreign keys not working
Date Mon, 30 Jan 2006 21:07:58 GMT
You need to have the  autoIncrement=true attribute set 
on the Segment_ID column definition in the Schema XML
(as well define the idMethod).


From: Patrick Carl [mailto:patrick.carl@web.de]
Sent: Mon 1/30/2006 9:56 AM
To: Apache Torque Users List
Subject: Re: convenience methods to handle foreign keys not working

Hash: SHA1


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


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: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


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

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.

View raw message