openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From areider <>
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

class Lot 
        @OneToMany(mappedby="lot",cascade =
        List<Car> carList; 
        @OneToMany(mappedby="lot",cascade =
        List<SalesPerson> salesPersonList; 
class Car 
        String lotFK; 
        String salesPersonFK; 
        Lot lot; 
        SalesPerson salesPerson; 
class SalesPerson 
        Lot lot; 
        @OneToMany(mappedBy="salesPerson"cascade =
        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: 

// carList 
// salesPersonList 

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
- 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

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:
Sent from the OpenJPA Users mailing list archive at

View raw message