openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "srini.krish" <>
Subject Inconsistent behaviour with Bi-directional One to Many Mapping.
Date Wed, 01 Apr 2009 17:29:39 GMT

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 {
    private int Id;
    private String Name;

    @OneToMany (cascade=CascadeType.ALL, mappedBy="person")
    private Collection<Address> addresses;
public class Address {
    private int id;

	@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).


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,
View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message