Hi Daryl,
A JOIN FETCH will eagerly load the collection for you, but should return one
reference to the entity for each element in the collection. I'm working on
fixing this under OPENJPA-894 (proceeding slowly though).
Adding a distinct clause will filter out these duplicates (but there are
issues there as well : OPENJPA-1365).
When it's all working you could use a query like this :
Query q = em.createQuery("SELECT DISTINCT o from A as o JOIN FETCH o.bCol");
If your goal is to selectively eagerly load a collection I believe this is
the vendor agnostic syntax you want..
Hope this helps,
-mike
On Wed, Nov 4, 2009 at 7:48 PM, Daryl Stultz <daryl@6degrees.com> wrote:
> On Wed, Nov 4, 2009 at 4:07 PM, Daryl Stultz <daryl@6degrees.com> wrote:
>
> > Hello,
> >
> > I'm wondering if anyone has seen something like this:
> >
> > <openjpa-1.2.1-r752877:753278 nonfatal general error>
> > org.apache.openjpa.persistence.PersistenceException: 5
> >
>
> I've run into this on 2 occasions with different fields in one entity. I
> can
> get around it in both cases by changing a fetch from EAGER to LAZY. So I
> have the entity A which has a collection of B which is set to LAZY. B has a
> field C that is set to EAGER. I retrieve like this:
>
> query = em.createQuery("select o from A as o");
> ((QueryImpl) query).getFetchPlan().addField(A.class, "bCol"); // bCol is
> collection of B
>
> The field B.c is defined like so
>
> @ManyToOne(fetch = FetchType.EAGER, optional = false)
> @JoinColumn(name = "cid", nullable = false)
> @ForeignKey
> private C c;
>
> This has also happened on another field of B that is nullable/optional.
>
> Right now the only way for me to feel the system is secure is to change
> everything to LAZY and put fetchPlan addFields all over. Please tell me I
> don't have to do that!
>
> Thanks.
>
> --
> Daryl Stultz
> _____________________________________
> 6 Degrees Software and Consulting, Inc.
> http://www.6degrees.com
> mailto:daryl@6degrees.com
>
|