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 Wed, 01 Feb 2006 13:49:01 GMT
Unfortunately, you should consider the generated XML as
a starting point and not a finished product.  It gets it
90% right, but leaves out things like autogenerate, indices,
and unique constraints.  Some of it's field choices sometimes
don't match what you want (fix char rather than varchar from
MS SQL).

To be fair, most of this is because these are areas that are
not too standardized across SQL Servers (e.g. Autoincrement
in not really an SQL standard, just a defacto one...).  This
makes it very hard to make a generalize extraction routine
from the SQL meta-data.

On the bright side, once you have the basic schema set up,
it's not hard to maintain.  For new tables, I tend to lay 
them out in the XML, then generate the OM/SQL and then grab the
SQL statement to create the new table from torque's output and
run it on the server.

For new columns, I just add them via the DB tool and then add 
them to the XML.

Occationally, if I'm doing a major change, I'll lay everything
out using the DB tools.  Then, I'll generate the full XML schema
and compare with the old. (Plus, I have some DB tools that will 
generate "alter" scripts by comparing db schema's to create 
upgrade scripts.)

Of course, keep in mind that once you've got your schema 
captured in XML, you can now generate code and db create
scripts for any DB that Torque supports.  Personally, I use
MySQL at home and MS SQL at work.  And am looking at a 'lite
variation for our web designers using HyperSQL that can be
quickly installed on their personal machines.  I could never 
do that without Torque.

> -----Original Message-----
> From: Dennis Vredeveld [mailto:vredeveld@imst.de] 
> Sent: Wednesday, February 01, 2006 4:20 AM
> To: Greg Monroe; Apache Torque Users List
> Subject: 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


Mime
View raw message