openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From areider <open...@reider.net>
Subject Order of insert
Date Thu, 04 Nov 2010 10:41:50 GMT

I have a model, which for purposes of my question, includes a structure like
this: 

class Lot 
        @OneToMany(mappedby="lot",cascade =
{CascadeType.MERGE,CascadeType.PERSIST})) 
        List<Car> carList; 
        @OneToMany(mappedby="lot",cascade =
{CascadeType.MERGE,CascadeType.PERSIST})) 
        List<SalesPerson> salesPersonList; 
class Car 
        @Column 
        String lotFK; 
        @Column 
        String salesPersonFK; 
        @ManyToOne 
        Lot lot; 
        @ManyToOne 
        SalesPerson salesPerson; 
class SalesPerson 
        @ManyToOne 
        Lot lot; 
        @OneToMany(mappedBy="salesPerson"cascade =
{CascadeType.MERGE,CascadeType.PERSIST})) 
        List<Car> carList; 

So cars are owned by lots and salesPersons and has non-nullable FK's to
both, with RI. 

When persisting a lot such as: 

lot1 
// carList 
--ford 
// salesPersonList 
--john 
----ford 

it seems JPA just does a top down traversal of the graph for the insert
order. Ie ford is inserted before john, which violates the RI for a Car. 

I tried a few things: 
- <property name="openjpa.jdbc.UpdateManager" value="operation-order"/> in
persistence.xml 
- annotating the foreign keys with @ForeignKey (then openJpa excludes the
column from insert, which then fails because the field is non-nullable) 
- removing the mapping Lot:car; ( works but I need the mapping). 
- defining Lot::salesPersonList ahead of Lot::carList. 
- NOT cascading persist from Lot to carList. 
- in @PrePersist of Lot, clear the carList, and JPA saves them later in the
carLists of salesPersons. A real hack, but happens to work  because in the
real model, the graph will always be complete with respect to cars and
salesPersons. 

Any other options for inducing the correct order or the inserts?


This is in  openJPA version that comes with IBM RAD7.5.5, which appears to
be 1.2.3.
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Order-of-insert-tp5704835p5704835.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Mime
View raw message