Hi John, Good detective work with the Google searching. It sounds like you hit a classic problem with the RuntimeUnenhancedClasses support. If the OneToMany is not loaded immediately (ie. EAGER), there was no hook in place to cause the loading at a later time.
But, if you are using one of the Enhancement mechanisms [1], then you should not see this problem. If you interrogate the A entity instance via a debugger, then the LAZY configured "bs" should be null. But, once you call getBs(), then OpenJPA should be loading that collection. My guess is that although you have verified that the build-time enhancement is actually doing some work (due to the larger class size), you may actually be running against non-enhanced entities. Just a guess. What version of OpenJPA are running with? In the OpenJPA 2.0 code base, we have actually disabled this RuntimeUnenhancedClasses by default due to the unexpected processing that occurs with this type of enhancement. If you are running with an older version of OpenJPA, then I would suggest using this property. This will ensure that OpenJPA does not fall back to this UnenhancedClasses sub-classing support. So, if you have a problem with the proper build-time or run-time enhancement processing, you'll get flagged and an error message will be posted. <property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/> Good luck, Kevin [1] http://webspherepersistence.blogspot.com/2009/02/openjpa-enhancement.html On Mon, Dec 13, 2010 at 6:33 AM, John Zhang <[email protected]> wrote: > 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! > > > >
