Dear All,

This is driving me nuts - I must be doing somethin wrong surely ?  I'm just
trying to load some objects previously stored to a database, but I'm finding
that the rows in the second table representing the Vecto elements are
deleted in a most odd way.  Surely these rows should be left alone ?  Please
help...

Attached is the database & mapping xml files, which are adapted from the
examples, and below is the relevant methods from VectorTest with sample
output - the behaviour is seen after the second execution, but it happens
with a more complex program I'm doing with the same behaviour.


    void populateDB( PrintWriter writer )
        throws Exception
    {
        Database      db;
        Product       product;
        ProductDetail detail;

        db = _jdo.getDatabase();

        db.begin();
        writer.println( "Begin transaction" );

        product = new Product();
        product.setName( "Greenhouse" );
        writer.println( "Creating new product: " + product );

        detail = new ProductDetail();
        detail.setName("Glass");
        product.addDetail(detail);

        detail = new ProductDetail();
        detail.setName("Door");
        product.addDetail(detail);


        db.create( product );


        product = new Product();
        product.setName( "Vegetable" );
        writer.println( "Creating new product: " + product );

        detail = new ProductDetail();
        detail.setName("colour");
        product.addDetail(detail);

        detail = new ProductDetail();
        detail.setName("shape");
        product.addDetail(detail);

        db.create( product );

        writer.println( "Commit transaction" );
        db.commit();

        db.close();
    }



    void queryDB( PrintWriter writer )
        throws Exception
    {
        Database      db;
        Product       product;
        ProductDetail detail;
        OQLQuery productOql;
        QueryResults  results;

        db = _jdo.getDatabase();

        db.begin();

        writer.println( "Begin transaction" );

        // Look up the product and if found in the database,
        // delete this object from the database
        productOql = db.getOQLQuery( "SELECT p FROM test.Product p " );
        results = productOql.execute();
        while ( results.hasMore() ) {
            product = (Product) results.next();
            writer.println( "Found this product : " + product );
            writer.println(product.getDetails());
        }


        db.commit();

        db.close();
    }





F:\JBuilder4\jdk1.3\bin\javaw -classpath
"F:\work\castor\CastorTest\classes;F:\castor-0.9.3src\castor-0.9.3\lib\servl
et.jar;F:\castor-0.9.3src\castor-0.9.3\lib\jndi_1.2.1.jar;F:\castor-0.9.3src
\castor-0.9.3\lib\ant1_3.jar;F:\castor-0.9.3src\castor-0.9.3\lib\jakarta-reg
exp-1.1.jar;F:\castor-0.9.3src\castor-0.9.3\lib\xslp_1.1d.jar;F:\castor-0.9.
3src\castor-0.9.3\lib\xerces-J_1.4.0.jar;F:\castor-0.9.3src\castor-0.9.3\lib
\junit_3.5.jar;F:\castor-0.9.3src\castor-0.9.3\lib\jtf-0.1.jar;F:\castor-0.9
.3src\castor-0.9.3\lib\idb.jar;F:\castor-0.9.3src\castor-0.9.3\lib\hsqldb.ja
r;F:\castor-0.9.3src\castor-0.9.3\lib\ldapjdk_4.1.jar;F:\castor-0.9.3src\cas
tor-0.9.3\lib\jta1.0.1.jar;F:\castor-0.9.3src\castor-0.9.3\lib\jdbc-se2.0.ja
r;F:\castor-0.9.3src\castor-0.9.3\lib\ant1_3_optional.jar;F:\castor-0.9.3src
\castor-0.9.3\lib\XMLDiff_0.2.jar;F:\castor-0.9.3src\castor-0.9.3\lib\postgr
esql_7.1beta.jar;F:\castor-0.9.3\castor-0.9.3.jar;F:\castor-0.9.3\castor-0.9
.3-xml.jar;F:\castor-0.9.3\jdbc-se2.0.jar;F:\castor-0.9.3\jta1.0.1.jar;F:\JB
uilder4\jdk1.3\demo\jfc\Java2D\Java2Demo.jar;F:\JBuilder4\jdk1.3\jre\lib\i18
n.jar;F:\JBuilder4\jdk1.3\jre\lib\jaws.jar;F:\JBuilder4\jdk1.3\jre\lib\rt.ja
r;F:\JBuilder4\jdk1.3\jre\lib\sunrsasign.jar;F:\JBuilder4\jdk1.3\lib\dt.jar;
F:\JBuilder4\jdk1.3\lib\tools.jar"  test.VectorTest
[test] Key generator HIGH/LOW has been instantiated, parameters:
{key-column=TableName, table=seq, grab-size=10, value-column=MaxPKValue}
[test] SQL for creating test.Product: INSERT INTO prod (id,name) VALUES
(?,?)
[test] SQL for deleting test.Product: DELETE FROM prod WHERE id=?
[test] SQL for updating test.Product: UPDATE prod SET name=? WHERE id=? AND
name=?
[test] SQL for loading test.Product:  SELECT prod.name,prod_detail.id FROM
prod LEFT OUTER JOIN prod_detail ON  (prod.id=prod_detail.prod_id) WHERE
prod.id=?
[test] SQL for creating test.ProductDetail: INSERT INTO prod_detail
(id,prod_id,name) VALUES (?,?,?)
[test] SQL for deleting test.ProductDetail: DELETE FROM prod_detail WHERE
id=?
[test] SQL for updating test.ProductDetail: UPDATE prod_detail SET
prod_id=?,name=? WHERE id=? AND prod_id=? AND name=?
[test] SQL for loading test.ProductDetail:  SELECT
prod_detail.prod_id,prod_detail.name FROM prod_detail WHERE prod_detail.id=?
[test] Begin transaction
[test] Creating new product: 0 Greenhouse
[test] Castor: Creating test.Product (null)
[test] Creating new product: 0 Vegetable
[test] Castor: Creating test.Product (null)
[test] Commit transaction
[test] Castor: Creating test.ProductDetail (null)
[test] Castor: Creating test.ProductDetail (null)
[test] Castor: Creating test.ProductDetail (null)
[test] Castor: Creating test.ProductDetail (null)
[test] Begin transaction
[test] SELECT prod.id,prod.name,prod_detail.id FROM prod LEFT OUTER JOIN
prod_detail ON  (prod.id=prod_detail.prod_id)
[test] Castor: Loading test.Product (1)
[test] Found this product : 1 Greenhouse
[test] []
[test] Castor: Loading test.Product (2)
[test] Found this product : 2 Vegetable
[test] []
[test] Castor: Loading test.Product (11)
[test] Found this product : 11 Greenhouse
[test] []
[test] Castor: Loading test.Product (12)
[test] Found this product : 12 Vegetable
[test] []
[test] Castor: Loading test.Product (21)
[test] Found this product : 21 Greenhouse
[test] []
[test] Castor: Loading test.ProductDetail (35)
[test] Castor: Loading test.ProductDetail (36)
[test] Castor: Loading test.Product (22)
[test] Found this product : 22 Vegetable
[test] [35 Glass, 36 Door]
[test] Castor: Loading test.Product (31)
[test] Found this product : 31 Greenhouse
[test] [35 Glass, 36 Door]
[test] Castor: Loading test.Product (32)
[test] Found this product : 32 Vegetable
[test] [35 Glass, 36 Door]
[test] Castor: Loading test.ProductDetail (41)
[test] Castor: Loading test.ProductDetail (42)
[test] Castor: Loading test.Product (41)
[test] Found this product : 41 Greenhouse
[test] [41 Glass, 42 Door]
[test] Castor: Loading test.ProductDetail (43)
[test] Castor: Loading test.ProductDetail (44)
[test] Castor: Loading test.Product (42)
[test] Found this product : 42 Vegetable
[test] [43 colour, 44 shape]
[test] Castor: Creating test.ProductDetail (null)
[test] Castor: Creating test.ProductDetail (null)
[test] Castor: Removing test.ProductDetail (35)
[test] Castor: Removing test.ProductDetail (36)
[test] Castor: Removing test.ProductDetail (41)
[test] Castor: Removing test.ProductDetail (42)
[test] Castor: Removing test.ProductDetail (43)
[test] Castor: Removing test.ProductDetail (44)
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>

  <key-generator name="HIGH/LOW">
    <param name="table" value="seq"/>
    <param name="key-column" value="TableName"/>
    <param name="value-column" value="MaxPKValue"/>
    <param name="grab-size" value="10"/>
  </key-generator>


  <!--  Mapping for Product  -->
  <class name="test.Product"
         identity="id" key-generator="HIGH/LOW">
    <description>Product definition</description>
    <map-to table="prod" />
    <field name="id" type="integer">
      <sql name="id" type="integer" />
    </field>
    <field name="name" type="string">
      <sql name="name" type="char" />
    </field>
    <!-- Product has reference to ProductDetail
         many details per product  -->
    <field name="details" type="test.ProductDetail" required="true"
           collection="vector">
      <sql many-key="prod_id"/>
    </field>

  </class>


  <!--  Mapping for Product Detail -->
  <class name="test.ProductDetail" identity="id" depends="test.Product"  key-generator="HIGH/LOW">
    <description>Product detail</description>
    <map-to table="prod_detail" />
    <field name="id" type="integer">
      <sql name="id" type="integer"/>
    </field>
    <field name="product" type="test.Product">
      <sql name="prod_id" />
    </field>
    <field name="name" type="string">
      <sql name="name" type="char"/>
    </field>
  </class>




</mapping>

<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor JDO Configuration DTD Version 1.0//EN"
                           "http://castor.exolab.org/jdo-conf.dtd";>
<database name="test" engine="hsql" >
<driver class-name="org.hsqldb.jdbcDriver"
          url="jdbc:hsqldb:hsql://localhost">
    <param name="user" value="sa" />
    <param name="password" value="" />
  </driver>
  <mapping href="etc/simplemapping.xml" />
</database>


simplecreate.sql

Product.java

ProductDetail.java

VectorTest.java

Reply via email to