db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sperlich, Tino" <t.sperl...@hpc-hamburg.de>
Subject AW: defaultIdMethod="none"
Date Tue, 31 Aug 2004 10:17:07 GMT
Hallo,

after having a closer look at the sources and the api docs,
Hennings posting is the right path to follow:

defaultIdMethod="autoincrement" is exactly doing what you need:
Upon insertion of a record it doesn't create 
a primary key value itself, but reads the 
value inserted for it from the db.

so firstly you should check the value of ab322 after insert
(better still to use ab322.save()),
then you should debug into your ad.setAddressB322() code to
see what and if the idaddress is mapped correctly from ab322.idaddress to 
ad.idaddress.

Hope that helps,

Tino

-----Urspr√ľngliche Nachricht-----
Von: Ferruh Zamangoer [mailto:ferruh.zamangoer@gistec-online.de]
Gesendet: Dienstag, 31. August 2004 11:43
An: Apache Torque Users List
Betreff: AW: defaultIdMethod="none"


Sorry I have seen that the data is inserted into the AddressB322 table
correctly, but how can I set the references to the table  AddressDelpoint,
AddressEmailadd. My understanding is that the data is inserted correctly by
the underlying database, but the ab322 Object becomes no data back or have
not the actual primaryKey???



	AddressB322 ab322 = new AddressB322();
	ab322.setAdminarea("FRA");
	ab322.setCity("Frankfurt" +  System.currentTimeMillis());
	ab322.setCountry("Hessen");
	ab322.setPostcode("60313");
	AddressB322Peer.doInsert(ab322);

	AddressDelpoint ad = new AddressDelpoint();
	ad.setAddressB322(ab322);				//references
	//ad.setIdaddress(ab322.getIdaddress());
	ad.setDelpoint("Frankfurt");
	ad.save();

	AddressEmailadd aed = new AddressEmailadd();
	aed.setAddressB322(ab322);				//references
	//aed.setIdaddress(ab322.getIdaddress());
	aed.setEmailadd("ferruh.zamangoer@gistec-online.de");
	aed.save();








-----Urspr√ľngliche Nachricht-----
Von: Ferruh Zamangoer [mailto:ferruh.zamangoer@gistec-online.de]
Gesendet: Dienstag, 31. August 2004 10:26
An: Apache Torque Users List
Betreff: defaultIdMethod="none"


Hi,

can anybody tell me something more about the "none" option in the
defaultIdMethod. Few days ago I have posted my Problem with the triggers and
Tino Sperlich has wrote this message.

<cut>
HI,

so you cannot edit the database triggers and schemas,
but you can edit the torque schema.xml?

So you need to set in the schema.xml the defaultIdMethod="none" as
Robert Bowen pointed out.

This way torque will not try to create a primary key value from a
sequence but leave that all up to your code, e.g. your database trigger.

So change the schema, regenerate torque classes and than inserts etc.
will be processed without primary key generation from torque.

Regards,
Tino Sperlich
</cut>

I try the suggestion from Tino with the following Code:


JAVA CODE:
----------

AddressB322 ab322 = new AddressB322();
ab322.setAdminarea("FRA");
ab322.setCity("Frankfurt" +  System.currentTimeMillis());
ab322.setCountry("Hessen");
ab322.setPostcode("60313");
ab322.save();

System.out.println("TORQUE: " +  ab322.getIdaddress());

Database Settings in schema.xml:
--------------------------------
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE database SYSTEM
 "http://db.apache.org/torque/dtd/database_3_1.dtd">

<database
  name="ingeo"
  defaultIdMethod="none"
  skipSql="true">

<!-- #### TABLE ADDRESS_B322 ####-->

<table name="address_b322" description="Address_B322">
<column
  name="idaddress"
  required="true"
  primaryKey="true"
  type="INTEGER"
  size="5"
  description="ID Address"/>
<column
  name="city"
  required="false"
  type="VARCHAR"
  size="4000"
  description="City"/>
<column
  name="adminarea"
  required="false"
  type="VARCHAR"
  size="4000"
  description="Admin Area"/>
<column
  name="postcode"
  required="false"
  type="VARCHAR"
  size="4000"
  description="Post Code"/>
<column
  name="country"
  required="false"
  type="VARCHAR"
  size="4000"
  description="Country"/>
<id-method-parameter name="ADDRESS_ID_SEQ" value="ADDRESS_ID_SEQ"/>
</table>
</database>

sequence:
--------------
ADDRESS_ID_SEQ

Trigger for this table:
------------------------
TRIGGER "ADVMIS".Address_BIns
BEFORE INSERT ON ADDRESS_B322
FOR EACH ROW
DECLARE
   nummer  NUMBER;
BEGIN
   SELECT Address_id_Seq.NEXTVAL INTO nummer  FROM sys.dual;
   :NEW.idAddress := nummer;
END;

output of the JAVA_CODE
-----------------------

System.out.println("TORQUE: " +  ab322.getIdaddress()); ==> 0 ???????

After my understanding, when I'am using the defaultIdMethod="none" the Id's
are not generated by Torque and the underlying Database particularly the
Trigger generates the ID ?????

Regards
Ferruh









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


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


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