Thanks very much Ned for the reply. I just make a
very simple case here.
I have two classes, one is com.MyOrder and one is com.OrderLine and a
mapping file, (see below).
To generate two MyOrder objects and store into a database, I did
        MyOrder order1 = new MyOrder(1, "First order");
        MyOrder order2 = new MyOrder(2, "Second order");

        OrderLine ordLine1 = new OrderLine(order1);
        OrderLine ordLine2 = new OrderLine(order1);
        OrderLine ordLine3 = new OrderLine(order2);
        OrderLine ordLine4 = new OrderLine(order2);
        OrderLine ordLine5 = new OrderLine(order2);
                        
        order1.addOrderLine(ordLine1);
        order1.addOrderLine(ordLine2);
        order2.addOrderLine(ordLine3);
        order2.addOrderLine(ordLine4);
        order2.addOrderLine(ordLine5);

        db.begin();
        db.create(order1);
        db.create(order2);
        db.commit();

So far, everything works fine. Now I start another JVM and do
        db.begin();             
                orderOql = db.getOQLQuery( "SELECT o FROM com.MyOrder o" );
                results = orderOql.execute();
                
                while ( results.hasMore() ) {
                        MyOrder order01 = (MyOrder) results.next();
                        _printOrder(order01); //print out order fields.
                }
                
        System.out.println(".....do commit");
        db.commit();

What I got is like:
[test] SELECT "ORDERS_S"."ID","ORDERS_S"."NAME","ORDERLINE_S"."ID" FROM
"ORDERLINE_S","ORDERS_S
" WHERE "ORDERS_S"."ID"="ORDERLINE_S"."ORDER_ID"(+)
[test] Castor: Loading com.OrderLine (1)
[test] Castor: Loading com.OrderLine (2)
[test] Castor: Loading com.MyOrder (1)
[from _printOrder] order is: First order
[from _printOrder] order Line Id is: 1
[from _printOrder] order Line Id is: 2
[test] Castor: Loading com.OrderLine (3)
[test] Castor: Loading com.OrderLine (4)
[test] Castor: Loading com.OrderLine (5)
[test] Castor: Loading com.MyOrder (2)
[from _printOrder] order is: Second order
[from _printOrder] order Line Id is: 1
[from _printOrder] order Line Id is: 2
[from _printOrder] order Line Id is: 3
[from _printOrder] order Line Id is: 4
[from _printOrder] order Line Id is: 5
.....do commit
[test] Castor: Removing com.OrderLine (3)
[test] Castor: Removing com.OrderLine (4)
[test] Castor: Removing com.OrderLine (5)

Here you can see that the orderLines of the second MyOrder( should be
orderline3,4,5) 
also pointed to the orderlines of the first order AND orderline(3,4,5) are
REMOVED
when do db.commit(). Did I do anything wrong here?

I appreciate your help!

ping
                        
##################class files and mapping file in below#####################
========class MyOrder============
package com;
import java.util.Vector;

public class MyOrder
{
    private int       _id;
        private Vector    _orderLines = new Vector();
        private String _name;

        public MyOrder() {}
        public MyOrder(int id, String name) {
                _id = id;
                _name = name;
        }

    public int getId()
    {
        return _id;
    }

    public void setId(int id)
    {
        _id = id;
    }

        public String getName()
        {
                return _name;
        }

        public void setName(String name)
        {
                _name = name;
        }

        public Vector getOrderLines()
        {
                return _orderLines;
        }

        public void addOrderLine(OrderLine orderLine)
        {
                if (!_orderLines.contains(orderLine)) {
                        _orderLines.addElement(orderLine);
                }
        }

        public void setOrderLines(Vector orderLine)
        {
                _orderLines.clear();
                        _orderLines = orderLine;
        }
}
========class OrderLine============
package com;

import java.util.Vector;
public class OrderLine
{
        private int       _id;
        private MyOrder _myOrder;
        public OrderLine() {}

        public OrderLine(MyOrder myOrder) {
                _myOrder = myOrder;
        }

        public OrderLine(int id, MyOrder myOrder) {
                _id = id;
                _myOrder = myOrder;
        }

        public int getId()
        {
                return _id;
        }

        public void setId(int id)
        {
                _id = id;
        }

        public MyOrder getMyOrder()
        {
                return _myOrder;
        }

        public void setMyOrder(MyOrder myOrder)
        {
                _myOrder = myOrder;
        }
}

========mapping file============
<!DOCTYPE databases PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
                           "http://castor.exolab.org/mapping.dtd";>
<mapping>
  <!--  Mapping for Order  -->
  <class name="com.MyOrder"
         identity="id">
    <description>Order definition</description>
    <map-to table="orders_s"/>
    <field name="id" type="integer">
      <sql name="id" type="integer" />
    </field>

    <field name="name" type="string">
      <sql name="name" type="char" />
    </field>

    <!-- Order has reference to OrderLine
         many OrderLines per Order  -->
    <field name="orderLines" type="com.OrderLine" required="true"
           laze="false" collection="vector">
      <sql many-key="order_id"/>
    </field>
  </class>

  <!--  Mapping for OrderLine  -->
  <class name="com.OrderLine" identity="id" depends="com.MyOrder"
                key-generator="MAX">
    <description>An order orderLine, any number of orderLines can belong to
                 the same order</description>
    <map-to table="orderline_s" />
    <field name="id" type="integer">
      <sql name="id" type="integer"/>
    </field>
  
    <field name="myOrder" type="com.MyOrder">
      <sql name="order_id"/>
    </field>
  </class>

</mapping>



----------------------------------------------------------------------- 
Ping Ding 



-----Original Message-----
From: Ned Wolpert [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 29, 2002 3:03 PM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] JDO QueryResults question


Can you include the code sample that shows what you're doing and your
mapping file?

--- Ping Ding <[EMAIL PROTECTED]> wrote:
> Hi, I got a problem about the JDO QueryResults.
> I stored two objects of class A and A has a collection field of class B.
> I start a new application, select every A ("SELECT a FROM A a" )and
> print
> out it. 
> When I do db.commit(),
> All B belongs to my second A object are removed from the database. It
> means
> that
> QueryResults.next() changes object status. Does any one has the similar
> problem?
> 
> ----------------------------------------------------------------------- 
> Ping Ding 
> 
> ----------------------------------------------------------- 
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>       unsubscribe castor-dev
> 


=====
Virtually,   Ned Wolpert <[EMAIL PROTECTED]>

"Who watches the watchmen?"  -Juvenal, 120 AD (4e75)

__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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

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

Reply via email to