openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "srini.krish" <srinivasan.kr...@gmail.com>
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 {
    @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
-- 
View this message in context: http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Many-Mapping.-tp2570464p2570464.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.


Mime
View raw message