When I write my query like
Code:
select o from Order o left join fetch o.orderLines where o.orderLines.quantity=5
the exception mentioned below is shown. the following works
Code:
from Order o left join fetch o.orderLines where o.orderLines.quantity=5
I thought that both queries are correct. If I am correct, than
I assume that this points to a problem in the parsing for a specific mapping.
When I change my mapping from a composite-element to a simple 1:n mapping for Order and OrderLine both query works.
See below my orginial mapping.
Code:
<hibernate-mapping package="de.laliluna.webstock">
<class name="Order" table="torder">
<id name="id">
<generator class="sequence">
<param name="sequence">torder_id_seq</param>
</generator>
</id>
<property name="number" type="string"></property>
<many-to-one name="customer" class="Customer">
<column name="customer_id" not-null="true"></column>
</many-to-one>
<list name="orderLines" table="torderline" cascade="all-delete-orphan">
<key column="order_id"></key>
<list-index column="list_index"></list-index>
<composite-element class="OrderLine" >
<parent name="Order" />
<property name="quantity" type="integer"></property>
<many-to-one name="article" column="article_id" class="Article" cascade="all"></many-to-one>
</composite-element>
</list>
</class>
and the 1:n mapping which does not cause the problem.
Code:
<hibernate-mapping package="de.laliluna.webstock">
<class name="Order" table="torder">
<id name="id">
<generator class="sequence">
<param name="sequence">torder_id_seq</param>
</generator>
</id>
<property name="number" type="string"></property>
<many-to-one name="customer" class="Customer">
<column name="customer_id" not-null="true"></column>
</many-to-one>
<list name="orderLines" table="torderline" cascade="all-delete-orphan">
<key column="order_id"></key>
<list-index column="list_index"></list-index>
<one-to-many class="OrderLine"/>
</list>
</class>
<class name="OrderLine" table="torderline">
<id name="id">
<generator class="sequence">
<param name="sequence">torderline_id_seq</param>
</generator>
</id>
<property name="quantity" type="integer"></property>
</class>
ExceptionCode:
10:10:27,000 DEBUG Collections:176 - Collection found: [de.lalilunaException in thread "main" java.lang.NullPointerException
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:175)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:637)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:466)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:643)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:279)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:227).webstock.Customer.orders#1], was: [de.laliluna.webstock.Customer.orders#1] (uninitialized)