You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Dennis Vredeveld <vr...@imst.de> on 2006/02/01 10:20:12 UTC

AW: convenience methods to handle foreign keys not working

Thanks, you are right: the idMethod and autoIncrement values were not set. I
didn't even know they had to be set manually, as my schema.xml has been
reverse engineered from an existing DB. Within the DB auto_increment has
been set.
So should Torque also automatically generated these properties for me or
should I get used to editing the schema.xml file manually after generating,
if I want to be able to write in the DB?

> -----Ursprüngliche Nachricht-----
> Von: Greg Monroe [mailto:Greg.Monroe@DukeCE.com]
> Gesendet: Monday, January 30, 2006 22:08
> An: Apache Torque Users List
> Betreff: RE: convenience methods to handle foreign keys not working
>
>
> 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
>
>
>
> -----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: torque-user-unsubscribe@db.apache.org
> > For additional commands, e-mail: torque-user-help@db.apache.org
> >
> -----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: 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.
>
>
>


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