Dears

I am new to OpenJPA, and currently I am using Spring 2.5 + OpenJPA, through 
Spring JpaTemplate, running on top of Tomcat 6 + JRE 6

The situation is that I have two classes A, B. A has a OneToMany relationship 
to 
B. I use joincolumn, and the code is like below:

class A {
....
    private Set<B> bs;

    @OneToMany(mappedBy = "a", fetch=FetchType.LAZY)
    public Set<B> getBs() {
        return bs;
    }
...
}

class B{
....
    private A  a;

    @ManyToOne
    @JoinColumns({ @JoinColumn(name = "id1"),
            @JoinColumn(name = "id2"),
            @JoinColumn(name = "id3") })
    public A getA() {
        return a;
    }
}

The problem is when I set the fetch=FetchType.EAGER, everything goes well, I 
can 
get "bs" in A instance. 

But if I change the fetch to FetchType.LAZY, the "bs" is always null, even I 
had 
access the getter, e.g. A.getBs().

After google, it said that the code should be enhanced using OpenJPA 
Enhancement 
Ant script, so I did it, and yes the class after enhancement is larger than 
original one. 

But "bs" is still null...

Could any expert to throw me some light? thanks a lot!



      

Reply via email to