Hellu again,
Ok, we made some progress and now are able to do "some" saving of our order, however appearantly we have some problem in the order we create and fill our persist objects.
Can some please give some insight in the correct order as I can't find it in the doc's neither faq/forums.
What we have:
- An Order object.
- A Ticket object.
- An OrderlineType object
- A Orderline object that has a many-to-one relation with an Order, Ticket
and OrderlineType.
- Ticket status object.
- An Ticket Status History table that has a many-to-one relation with the Ticket status object and a many-to-one relation with a Ticket object.
- The Orderline also has a Orderline Status and Orderline Status history object with the same relations as the Ticket history.
The Ticket and Orderline status objects, and the OrderlineType objects are stored in the database.
What we do:
1) Create a new order.
2) Create a new orderline and fill it. This means that the orderline also get connected to a new orderline history status object that is connected to a orderline status object that is retrieved from the datasource. It is also connected to the new Order.
3) Create ticket and fill it. idem as before concering the status objects. The ticket is connected to the new orderline.
4) Link the new Orderline to an existing OrderlineType that is retrieved from the data source.
5) Save the order.
Above doesn't work. I generates the errors that are listed above (previous mails in this thread). The errors take place when the order is saved in step 5. The error that hibernate give: it tries to insert the new orderline before inserting the new ticket.
Butttt what does work: in case that step 4) takes place after step 2).
I really have no idea why this makes any difference.
It thought: just create your objects, connect them and save the parent.... what am I missing here ??
Above also occurred in some other place. The Ticket is connected to a delivery channel object that is retrieved from the data source. This also has to be placed in the correct line in the code, otherwise we got the same error. We noticed that hibernate didn't give this error in case we changed the flushmode to COMMIT_ONLY, but I don't want that as (what I read from the doc) it means that you can retrieve stale data in that case.
Some other thing, which I think can explain if I have some more insight in the above:
The orderline is connected to the order through:
a) newOrderline.setOrder(newOrder);
b) newOrder.getOrderlines().add(newOrderline);
and that doesn't work, it generates the same error.
What does work: removing b).... but that is really strange to meeee... :(
We now are able to save the order and all his childs and are checking the stored data at this moment.
Buttt stilll, can someone please give some insight in above and where to look for ??
Regards,
Ed Bras
PS: we use hibernate 2.1.2
|