Pinaki, thank you for this comprehensive answer.

The new mapping now looks like this (in case I have overlooked something):

@Entity
public class Person {

        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE)
        private long id;

        @OneToMany(cascade=CascadeType.ALL)
        @JoinTable(name="PERSON_ADDRESS",
                  [EMAIL PROTECTED](name="PERSON_ID",
referencedColumnName="ID"),
                  [EMAIL PROTECTED](name="ADDRESS_ID",
referencedColumnName="ID"))
        private Set<Address> addresses = new HashSet<Address>();
}

@Entity
public class Address {

        @Id
        @GeneratedValue(strategy=GenerationType.SEQUENCE) 
        private long id;

        @ManyToOne
        @JoinColumn(table="PERSON_ADDRESS", referencedColumnName="ID")
        private Person person;
}


To cut a long story short: The schema looks good, but it is not working
either.



It seems to me that converting the bidirectional relationship to two
unidirectional ones (that happen to map to the same tables/columns) poses a
problem for OpenJPA (version 1.1.0):

Persisting new persons with addresses leads to duplicate entries in the
lookup-table
"address.setPerson(null)" causes an
org.apache.openjpa.util.OptimisticException: Optimistic locking errors were
detected when flushing to the data store.  The following objects may have
been concurrently modified in another transaction ...

with SQL: UPDATE TEST.PERSON_ADDRESS SET PERSON_ID = ? WHERE ADDRESS_ID = ?
[params=(null) null, (long) 2]
Deleting persons with addresses also leads to OptimisticExceptions (probably
due to duplicate delete statements for the join-table) 


I would create a bug report/enhancement request, if you would indicate me,
which of the tested mappings should work with OpenJPA.


-- Frank
-- 
View this message in context: 
http://n2.nabble.com/bidirectional-one-to-many-relationship-with-join-table-tp678479p682369.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to