Hi all,

        I have two tables, ORDERS and ORDER_PARAMETERS, as you can see in mapping 
below. The problem is that when I try to store an order (with its parameters) castor 
is returning a wrong ID. 

        This is the log of the program that prints the ID just after db.create():

db.create( mapObj );
logger.debug("Creating object with ID=" + mapObj.id);

DEBUG [Thread-6] (Log4jStringWriter.java:62) - [castor] Castor: Creating 
es.comunitel.mslv.connectors.jdo.MappingObjWrapper (null)
DEBUG [Thread-6] (Log4jStringWriter.java:62) - [castor] Castor: Creating 
es.comunitel.util.castor.Attribute (null)
DEBUG [Thread-6] (Log4jStringWriter.java:62) - [castor] Castor: Creating 
es.comunitel.util.castor.Attribute (null)
DEBUG [Thread-6] (Log4jStringWriter.java:62) - [castor] Castor: Creating 
es.comunitel.util.castor.Attribute (null)
DEBUG [Thread-6] (Log4jStringWriter.java:62) - [castor] Castor: Creating 
es.comunitel.util.castor.Attribute (null)
DEBUG [Thread-6] (GenericEventHandler.java:262) - Creating object with ID=410065697

        But the ID in the database is 9000000290. The trigger that gives this ID is:

TRIGGER TRG_ORDERS_ID
BEFORE INSERT ON ORDERS
FOR EACH ROW
BEGIN
  IF :NEW.ID IS NULL THEN
    SELECT '9' || lpad(to_char(ORDER_ID_GENERATOR.nextval),9,'0') INTO :new.ID FROM 
DUAL;
  END IF;
END;

        I execute directly the SQL that castor use to insert new records and it works 
fine (returning the correct ID), so I don't know what is happening.

INSERT INTO "ORDERS" ("ORDER_TYPE_CODE","READY_FOR_PROVISION")
VALUES (?,?) RETURNING "ID" INTO ?


This is the mapping that I'm using:

<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>

  <key-generator name="SEQUENCE" alias="TRIGGER_KEYGEN">
    <param name="trigger"   value="true"/>
    <param name="returning" value="true"/>
  </key-generator>
  
<class name="es.comunitel.mslv.connectors.jdo.MappingObjWrapper" identity="id" 
key-generator="TRIGGER_KEYGEN" extends="es.comunitel.mslv.connectors.jdo.MappingObj">
    <description>Orden de activacion</description>
    <map-to table="ORDERS"/>
    <cache-type type="none"/>
    
    <field name="id" type="integer"> 
       <sql name="ID" type="integer" /> 
    </field>
    <field name= "orderTypeCode" type="string"> 
        <sql name="ORDER_TYPE_CODE" type="varchar" /> 
    </field>
    <field name= "readyForProvision" type="string"> 
       <sql name="READY_FOR_PROVISION" type="varchar" /> 
    </field>
    <field name="attributes" type="es.comunitel.util.jdo.Attribute" 
collection="vector">
       <sql many-key="ORDER_ID"/>
    </field>

  </class>
  
  <class name="es.comunitel.util.jdo.Attribute" identity="primary_id" 
key-generator="TRIGGER_KEYGEN" 
depends="es.comunitel.mslv.connectors.jdo.MappingObjWrapper">
    <cache-type type="none"/>
    <map-to table="ORDER_PARAMETERS"/>
    
    <field name="primary_id" type="integer"> 
       <sql name="ID_KEY" type="integer" /> 
    </field>
    <field name="foreign_id" type="integer"> 
       <sql name="ORDER_ID" type="integer" /> 
    </field>
    <field name="key" type="string"> 
       <sql name="PARAMETER_NAME" type="varchar" /> 
    </field>
    <field name="value" type="string"> 
       <sql name="PARAMETER_VALUE" type="varchar" /> 
    </field>
  </class>
   
</mapping>

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to