> However > <property name="openjpa.jdbc.Schemafactory" value="native(ForeignKeys=true)"/> > didnt solve the issue..
That does not sound good. Please note that the property name should be "openjpa.jdbc.SchemaFactory" and not "openjpa.jdbc.Schemafactory". Please post a self-contained test case + domain class + persistence.xml + assertion failure stack trac for further investigation. Hi Pinaki, Thanks a lot for your help.. The property <property name="openjpa.jdbc.UpdateManager" value="operation-order"/> helped me solve the issue.. However <property name="openjpa.jdbc.Schemafactory" value="native(ForeignKeys=true)"/> didnt solve the issue.. Best Regards, Srini On Fri, Apr 3, 2009 at 10:49 AM, Pinaki Poddar (via Nabble) <ml-user+12775-494103...@n2.nabble.com> wrote: > Hi, > OpenJPA can reorder the SQL to honor the existing foreign key constraints > in the database schema. But you need to tell OpenJPA to read the foreign key > information from the schema. To do this > <property name="openjpa.jdbc.Schemafactory" > value="native(ForeignKeys=true)"/> > > The other possibility is to choose an update strategy that maintains the > SQL in in-memory operation order. > <property name="openjpa.jdbc.UpdateManager" value="operation-order"/> > > > > > srini.krish wrote: > Hi , > I am trying to create a bidirectional one to many mapping and seeing > inconsistent behaviour. If I enable trace persistence succeeds and if I > disable it, it fails. The failure is due to foreign key violation. I think > its due to the order of the execution of insert statements. The dependent > table is inserted with rows first. > > Here is the outline of mapping I have done. > (A person can have one or more address. Each address has an unique id and a > person associated with it) > public class Person { > @Id > private int Id; > > @Basic > private String Name; > > @OneToMany (cascade=CascadeType.ALL, mappedBy="person") > @OrderBy > private Collection<Address> addresses; > } > > public class Address { > @Id > private int id; > > @ManyToOne > @JoinColumn(name="PersonId", nullable=false) > private Person person; > } > > I try the following code > > //Create new person > // Create new addresses(2) > //To each address add the same person. > //To the person add addressCollection.(size 2). > > em.getTransaction().begin(); > em.persist(person); > em.getTransaction().commit(); > > When I do this, sometimes person is first persisted and address is next. > This case passes. (This happen when trace is on). > > The other times, address is persisted first. This fails for want of person > id. (This happens when trace is at Info level). > > Can anybody please help me, if I am missing something? > > Best Regards, > Srini > > Pinaki Poddar http://ppoddar.blogspot.com/ > > http://www.linkedin.com/in/pinakipoddar > OpenJPA PMC Member/Committer > JPA Expert Group Member > > ________________________________ > This email is a reply to your post @ > http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Many-Mapping.-tp2570464p2579010.html > You can reply by email or by visting the link above. > > ----- Pinaki Poddar http://ppoddar.blogspot.com/ http://www.linkedin.com/in/pinakipoddar OpenJPA PMC Member/Committer JPA Expert Group Member -- View this message in context: http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Many-Mapping.-tp2570464p2579145.html Sent from the OpenJPA Users mailing list archive at Nabble.com.