Sorry I didn't ask this in my initial email.... what version of OpenJPA are
you using, and how are you enhancing your Entities?

On Tue, Oct 18, 2011 at 3:02 AM, Tobias Trelle <tobias.tre...@codecentric.de
> wrote:

> Dear Rick,
>
>
> Rick Curtis wrote:
> >
> > How are you mapping this relationship? Can you post code snippets from
> > both
> > sides of the relationship?
> >
>
> Here's the full code of my minial example:
>
> @Entity
> public class A {
>
>    @Id
>    int id;
>
>    @OneToOne(cascade = CascadeType.ALL)
>    @JoinColumn(name = "id")
>    private B b;
>
>    public int getId() {
>        return id;
>    }
>
>    public void setId(int id) {
>        this.id = id;
>    }
>
>    public B getB() {
>        return b;
>    }
>
>    public void setB(B b) {
>        this.b = b;
>    }
>
> }
>
> @Entity
> public class B {
>
>    @Id
>    private int id;
>
>    @OneToOne(mappedBy = "b")
>    private A a;
>
>    public int getId() {
>        return id;
>    }
>
>    public void setId(int id) {
>        this.id = id;
>    }
>
>    public A getA() {
>        return a;
>    }
>
>    public void setA(A a) {
>        this.a = a;
>    }
>
> }
>
> My test code looks like this:
>
>        A a;
>        B b;
>        EntityManager em = getEntityManager();
>        EntityTransaction tx = em.getTransaction();
>
>        a = new A();
>        a.setId(1);
>
>        b = new B();
>        b.setId(1);
>
>        a.setB(b);
>        b.setA(a);
>
>        tx.begin();
>        em.persist(a);
>        tx.commit();
>
>        em.clear();
>        a = em.find(A.class, 1);
>
> which produces the following SQL select statement:
>
> TRACE 09:59:19 - <t 13741320, conn 11915355> executing prepstmnt 10188622
> SELECT t1.id, t2.id
>    FROM A t0 INNER JOIN B t1 ON t0.id = t1.id LEFT OUTER JOIN A t2 ON
> t1.id
> = t2.id
>    WHERE t0.id = ?
> [params=(int) 1]
> TRACE 09:59:19 - <t 13741320, conn 11915355> [15 ms] spent
>
> TIA,
> Tobias
> --
>
*Rick Curtis*

Reply via email to