I am using Hibernate-Version: 3.2.0.cr4 with SQL Server 2000, in a Tomcat 5.5.16 app with JDK 1.5.0_06.
I wish to retrieve the Orders for a given Rep, and force the immediate retrieval of the Rep records as well. I have sucessfully retrieved all Orders with their associated Reps (lazily) with the HQL
Code:
"from Order order"
This code
Code:
public static List loadOrders(String repCode)
{
Session session = HibernateUtil.getSession();
Query q = session.createQuery(
"from Order order left join fetch order.rep where rep.code > :repCode");
q.setParameter("repCode", repCode);
return q.list();
}
gives rise to the following error:
Code:
org.hibernate.QueryException: could not resolve property: rep of: com.myco.Order [from com.myco.Order di left join fetch di.rep where rep.code > :repCode]
The mappings have been created via the Eclipse Hibernate plugin and, as I said above, I can retrieve the orders and then navidate to the referenced Rep objects.
p.s. I have attempted to do the same using Criteria, but get the same result.
---------------------------------------------------------
Order extends the following generated class
Code:
package com.myco.base;
import java.io.Serializable;
public abstract class BaseOrder implements Serializable {
..
..
// constructors
public BaseOrder () {
initialize();
}
/**
* Constructor for primary key
*/
public BaseOrder (java.lang.Long id) {
this.setId(id);
initialize();
}
..
..
protected void initialize () {}
private int hashCode = Integer.MIN_VALUE;
// primary key
private java.lang.Long id;
// fields
private java.lang.String order;
..
..
// many to one
private com.myco.Rep rep;
..
..
/**
* Return the value associated with the column: repId
*/
public com.taylodge.commission.Rep getRep () {
return rep;
}
/**
* Set the value related to the column: repId
* @param rep the repId value
*/
public void setRep (com.taylodge.commission.Rep rep) {
this.rep = rep;
}
..
..
}
------------------------------------------------------------------------------------
Mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.myco">
<class
name="Order"
table="Order"
>
<meta attribute="sync-DAO">false</meta>
<id
name="Id"
type="java.lang.Long"
column="id"
unsaved-value="null"
>
<generator class="increment"/>
</id>
<!-- please tell Joe Hudson that the type 'nchar' could not be resolved.. defaulting to java.lang.String -->
<property
name="Order"
column="order"
type="java.lang.String"
not-null="true"
length="20"
/>
..
..
<many-to-one
name="Rep"
column="repId"
class="Rep"
not-null="true"
>
</many-to-one>
</class>
</hibernate-mapping>