Hi,
I have a QBE query where I have an Offence Entity, that has a foreign key Entity called 'FleetVehicle'. The associations are setup correctly I believe.
The Offence POJO Entity contains a FleetVehicle POJO/Entity but when I reference fleetVehicle.registrationNumber (I expect the QBE to do the join for me...) it bails complaining that it cannot resolve the field registrationNumber in the Offence entity??
Hibernate version:2.1.7
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.ocado.tracker.offences.pojo.Offence"
table="OFFENCES"
schema="trkdba"
>
<id
name="offenceUuid"
type="java.lang.Long"
column="OFFENCE_UUID"
>
<meta attribute="use-in-equals">true</meta>
<generator class="sequence">
<param name="sequence">OFFENCES_SEQ</param>
</generator>
</id>
<property
name="status"
type="java.lang.String"
column="STATUS"
not-null="true"
length="20"
/>
<property
name="authority"
type="java.lang.String"
column="AUTHORITY"
length="20"
/>
<property
name="ticketNumber"
type="java.lang.String"
column="TICKET_NUMBER"
length="20"
/>
<property
name="offence"
type="java.lang.String"
column="OFFENCE"
length="20"
/>
<property
name="datetimeOfOffence"
type="java.sql.Timestamp"
column="DATETIME_OF_OFFENCE"
length="7"
/>
<property
name="datetimeOfTicket"
type="java.sql.Timestamp"
column="DATETIME_OF_TICKET"
length="7"
/>
<property
name="parkingAttendant"
type="java.lang.String"
column="PARKING_ATTENDANT"
length="20"
/>
<property
name="site"
type="java.lang.Integer"
column="SITE"
length="22"
/>
<property
name="locOfOffence"
type="java.lang.String"
column="LOC_OF_OFFENCE"
length="30"
/>
<property
name="postcode"
type="java.lang.String"
column="POSTCODE"
length="8"
/>
<property
name="creditcardAuth"
type="java.lang.String"
column="CREDITCARD_AUTH"
length="10"
/>
<property
name="fine"
type="java.lang.Integer"
column="FINE"
length="22"
/>
<property
name="amountPaid"
type="java.lang.Integer"
column="AMOUNT_PAID"
length="22"
/>
<property
name="orderNumber"
type="java.lang.String"
column="ORDER_NUMBER"
length="10"
/>
<property
name="routeId"
type="java.lang.String"
column="ROUTE_ID"
length="10"
/>
<property
name="enteredBy"
type="java.lang.String"
column="ENTERED_BY"
not-null="true"
length="50"
/>
<property
name="assignedTo"
type="java.lang.String"
column="ASSIGNED_TO"
length="50"
/>
<property
name="lastModified"
type="java.sql.Timestamp"
column="LAST_MODIFIED"
not-null="true"
length="7"
/>
<property
name="lastModifiedBy"
type="java.lang.String"
column="LAST_MODIFIED_BY"
not-null="true"
length="50"
/>
<property
name="creationDate"
type="java.sql.Timestamp"
column="CREATION_DATE"
not-null="true"
length="7"
/>
<!-- Associations -->
<many-to-one
name="fleetVehicle"
class="com.ocado.tracker.fleet.pojo.FleetVehicle"
column="fleet_uuid"
not-null="false"
/>
<many-to-one
name="employee"
class="com.ocado.tracker.employees.pojo.Employee"
column="employee_uuid"
not-null="false"
/>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.ocado.tracker.fleet.pojo.FleetVehicle"
table="FLEET_VEHICLES"
schema="trkdba"
>
<id
name="fleetUuid"
type="java.lang.String"
column="FLEET_UUID"
>
<meta attribute="use-in-equals">true</meta>
<generator class="sequence">
<param name="sequence">FLEET_VEHICLES_SEQ</param>
</generator>
</id>
<property
name="registrationNumber"
type="java.lang.String"
column="REGISTRATION_NUMBER"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="trailerId"
type="java.lang.String"
column="TRAILER_ID"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="podOcadoId"
type="java.lang.String"
column="POD_OCADO_ID"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="podBuildNumber"
type="java.lang.String"
column="POD_BUILD_NUMBER"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="chassisNumber"
type="java.lang.String"
column="CHASSIS_NUMBER"
length="30"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="pdiDate"
type="java.sql.Timestamp"
column="PDI_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="tacho"
type="java.sql.Timestamp"
column="TACHO"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="engineSize"
type="java.lang.String"
column="ENGINE_SIZE"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="engineNumber"
type="java.lang.String"
column="ENGINE_NUMBER"
length="30"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="fridgeSerialNumber"
type="java.lang.String"
column="FRIDGE_SERIAL_NUMBER"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="liverycolour"
type="java.lang.Integer"
column="LIVERYCOLOUR"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="grossweight"
type="java.lang.String"
column="GROSSWEIGHT"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="ministryId"
type="java.lang.String"
column="MINISTRY_ID"
length="10"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="model"
type="java.lang.String"
column="MODEL"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="make"
type="java.lang.String"
column="MAKE"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="motDueDate"
type="java.sql.Timestamp"
column="MOT_DUE_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="taxDueDate"
type="java.sql.Timestamp"
column="TAX_DUE_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="serviceDueDate"
type="java.sql.Timestamp"
column="SERVICE_DUE_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="hire"
type="java.lang.String"
column="HIRE"
length="1"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="vehicleType"
type="java.lang.String"
column="VEHICLE_TYPE"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="value"
type="java.lang.Integer"
column="VALUE"
length="22"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="cover"
type="java.lang.String"
column="COVER"
length="20"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="lastModifiedDate"
type="java.sql.Timestamp"
column="LAST_MODIFIED_DATE"
not-null="true"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="lastModifiedBy"
type="java.lang.String"
column="LAST_MODIFIED_BY"
not-null="true"
length="50"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="creationDate"
type="java.sql.Timestamp"
column="CREATION_DATE"
not-null="true"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="motCompletedDate"
type="java.sql.Timestamp"
column="MOT_COMPLETED_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<property
name="serviceCompletedDate"
type="java.sql.Timestamp"
column="SERVICE_COMPLETED_DATE"
length="7"
>
<meta attribute="use-in-tostring">true</meta>
</property>
<!-- Associations -->
<!-- uni-directional one-to-many association to CustomerCard -->
<set name="offences"
lazy="true"
inverse="true"
cascade="save-update">
<key>
<column name="offence_uuid" />
</key>
<one-to-many class="com.ocado.tracker.offences.pojo.Offence"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
return (List) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
Example exampleOffence = Example.create(offence)
.ignoreCase()
.enableLike(MatchMode.ANYWHERE);
Criteria criteria = session.createCriteria(Offence.class);
if (validate(offence.getRegistrationNumber()))
{
// ilike does a case insensitve match
criteria.add(Expression.ilike("registrationNumber", offence.getRegistrationNumber(), MatchMode.ANYWHERE));
}
if (validate(offence.getStatus()))
{
criteria.add(Expression.ilike("status", offence.getStatus(), MatchMode.ANYWHERE));
}
if (offence.getOffenceUuid()!=null)
{
criteria.add(Expression.eq("offenceUuid", offence.getOffenceUuid()));
}
if (validate(offence.getOffence()))
{
criteria.add(Expression.ilike("offence", offence.getOffence(), MatchMode.ANYWHERE));
}
if (validate(offence.getRegistrationNumber()))
{
[b]criteria.add(Expression.ilike("fleetVehicle.registrationNumber", offence.getRegistrationNumber(), MatchMode.ANYWHERE)); }
return criteria.list();
}
});
[/b]
Full stack trace of any exception that occurs:
org.springframework.orm.hibernate.HibernateQueryException: could not resolve property: registrationNumber of:
com.ocado.tracker.offences.pojo.Offence; nested exception is net.sf.hibernate.QueryException: could not resolve property: registrationNumber of: com.ocado.tracker.offences.pojo.Offence
net.sf.hibernate.QueryException: could not resolve property: registrationNumber of: com.ocado.tracker.offences.pojo.Offence
at net.sf.hibernate.persister.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:50)
at net.sf.hibernate.expression.AbstractCriterion.getColumns(AbstractCriterion.java:42)
at net.sf.hibernate.expression.IlikeExpression.toSqlString(IlikeExpression.java:32)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:64)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3630)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.ocado.tracker.offences.dao.hibernate.OffencesDAOHibernate$1.doInHibernate(Unknown Source)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:312)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:289)
Name and version of the database you are using:Oracle 9i
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: