Bernd,

can I please see the complete stack trace ? Iow, does it happen on the 
db.update(order) or db.update(customer) ? In addition, I am asking myself 
whether what you describe is a valid use of Castor anyhow ? For 1:M relationships to 
work, to my knowledge, you need to be able to traverse the 
relationship both ways.

But then again, I may be wrong here ....

Werner

On Tue, 16 Mar 2004 12:01:20 +0100, Bernd Laengerich wrote:

>
>Hi,
>
>I am not sure wether my construct can be done with castor jdo, so let 
>me explain:
>
>Lets say we have a customer table and an order table. Every order has 
>one customer associated, so we have a one-to-many mapping.
>This works fine.
>
>For some reason I want to have a field (column) in customer that 
>normally is null, but sometimes refers to one specific order of that 
>customer.
>So I added this field and the mapping, everything is fine but to the 
>point, where I want to update my customer with a specific order, this 
>results in an "not created within this transaction", which is correct 
>as both instances already exists in the database and are not created 
>within one transaction. I use long transactions as described in the 
>documentation, all mappings are with <cache-type type="unlimited"> to 
>avoid expiration.
>
>My code looks something like this, part I _OR_ part II are used 
>before Part III, which is my problem. Very simplified just to give a 
>rough idea:
>
>// Part I:
>Customer customer = (Customer)db.load(Customer.class,somekey);
>...
>Order order = new Order();
>order.setCustomer(cust);
>order.setXYZ();
>db.create(order);
>...
>
>// Part II:
>Customer customer = (Customer)db.load(Customer.class,somekey);
>Order order = null;
>OQLQuery oql = db.getOQLQuery("SELECT o FROM my.Order o WHERE 
>customer = $1 AND somecondition = $2");
>oql.bind(customer);
>oql.bind(condition);
>QueryResults resset = oql.execute();
>if (resset.hasMore()) {
>       order = (Order) resset.nextElement();
>}
>
>//Part III:
>if (order.isCondition()) {
>       db.begin();
>       order.setBla(foo);
>       customer.setSpecialOrder(order);
>       db.update(order);
>       db.update(customer);
>       db.commit();
>}
>
>I tried to reload the order by doing a db.load(order.getId()), but 
>this leads to _another_ Customer instance (with the same id) being 
>loaded in the new Order instance.
>
>The only solution I see is to just store the Id of the order inside 
>customer as plain Integer, so I can load the instance from the data 
>base by id manually. Do I miss something?
>
>Bernd
>
>----------------------------------------------------------- 
>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