I've got a question - is it possible to use openJPA with database that has set 
foreign key constraints?

I've got two tables - order and order item. Order item has a column with 
order_id, which is PK for order table. In Java classes I set relationship as 
OneToMany for Order (with Collection of OrderItems field) and ManyToOne for 
OrderItem (with field of Order type). I put Cascadetype.PERSIST, REMOVE and 
MERGE to OneToMany annotation. When I try to invoke persist method on 
EntityManger - sometimes I receive errors causes by OpenJPA tries to persist 
OrderItem object (with value form Order foreign key) before persisting of Order 
object - that cause database to throw exception that foreign key is not present 
in Order table. It's very odd for me - because I can persist for example 2 
order object with no errors and then see this exception:
<openjpa-1.0.0-r420667:568756 nonfatal store error> 
org.apache.openjpa.util.StoreException: ERROR: insert or update on table 
"order_item" violates foreign key constraint "order_item_fk"

Is there any solution for this problem? Can I somehow point in which order 
object should be persist? In addition - I tried to persist order object that 
has list which consist of only one orderitem object.

I use OpenJPA 1.0.0 with PostgreSQL 8.2.4 and JDBC driver 
postgresql-8.2-505.jdbc3.jar and Glassfish v2 b57.

Thanks for any help!

Jakub Piechnik

Reply via email to