Hibernate version: 3.2.6.ga (latest)
I have a HQL problem using two fetch joins with between 2 entities and 1 value-typed component. I get a nullpointerexception while simular queries (without two fetch joins) succeed.
Here is my class setup:
A
Product has only one
Photo, and a photo has multiple
Thumbnail formats.
The corresponding classes are:
-Product (Entity)
-Photo (Entity)
-Thumb (composed class / value type / Embeddable)
Class cardinality:
Product <--1------1--> Photo <--1-----*--> Thumb
Code:
@Entity
public class Product {
...
@OneToOne
private Photo photo;
...
}
Code:
@Entity
public class Photo {
...
@CollectionOfElements
private Set<Thumb> thumbs = new HashSet<Thumb>();
...
}
Code:
@Embeddable
public class Thumb {
// contains only value types
}
Problem:I want to perform a single HQL/JPA query that fetches (and initializes) the photo and all corresponding all thumbs for a given product.
I tried the query:
Code:
from Product pr
join fetch pr.photo ph
join fetch ph.thumbs
and
Code:
from Product pr
join fetch pr.photo ph
join ph.thumbs
Which both fail with:
Code:
java.lang.NullPointerException
at org.hibernate.loader.BasicLoader.isBag(BasicLoader.java:71)
at org.hibernate.loader.BasicLoader.postInstantiate(BasicLoader.java:53)
at org.hibernate.loader.hql.QueryLoader.<init>(QueryLoader.java:96)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:181)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at org.hibernate.console.HQLQueryPage.setSession(HQLQueryPage.java:106)
The strange thing is that the following queries succeed:
Code:
from Product pr
join pr.photo ph
join fetch ph.thumbs
Code:
from Photo ph
join fetch ph.thumbs
Code:
from Product pr
join pr.photo ph
join ph.thumbs
Code:
from Product pr
join fetch pr.photo ph
Code:
from Product pr
join fetch pr.photo ph
Why do the first 2 queries fail?