This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Order by clause on child (Hibernate) not working

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I'm new to Hibernate.

I've a parent order_header mapped one-to-many to order_details (for every header there can be multiple details). I need to order by LINE_NUMBER on the child (order_detail).

Here's my java code


Session session = HibernateSession.currentSession();
Criteria crit = session.createCriteria(SalesOrderHeader.class);
crit.add(Expression.eq("batchId", batchId));
crit.addOrder(Order.asc("SalesOrderLine.id"));
results = crit.list();

when I run my java pgm I'm getting QueryException : Could not resolve Property SalesOrderLine.id of com.bos.order.process.resource.beans.SalesOrderHeader

Here's my parent

<hibernate-mapping>
<class name="com.bos.order.process.resource.beans.SalesOrderHeader" table="order_header" >
<id name="webPOKey" column="PO_KEY" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property name="status" column="stat_id" type="long" not-null="true"/>
<property name="orderSource" column="ORIGINATOR" type="string" length="50" not-null="true"/>

<bag name="orderDetail">
<key column="PO_KEY"/>
<one-to-many class="com.bos.order.process.resource.beans.SalesOrderLine"/>

</class>

</hibernate-mapping>

and the child

<hibernate-mapping>
<class name="com.bos.order.process.resource.beans.SalesOrderLine" table="order_detail">
<composite-id>
<key-property name="webPOKey" column="PO_KEY" type="long"/>
<key-property name="id" column="LINE_NUMBER" type="long" length="6"/>
</composite-id>
<property name="itemNumber" column="ITEM_CODE" type="string" />
<property name="description" column="DESCRIPTION" type="string" />

</class>
</hibernate-mapping>

Can someone help me?

Thanks
Maalti Iyer
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try

instead of
 
Greenhorn
Posts: 3
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Lasse Koskela wrote:Try

instead of



The above code is not working in CriteriaBuilder
 
Forget Steve. Look at this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!