I'm trying to create a query to fetch information from one table
TbDevice based on conditions in that table and another related table
TbCustDevice in the database.
Basically, the TbDevice table holds the device information and the TbCustDevice table holds additional information if the device has been assigned to a customer.
I suspect I need to use an inner join, based on this example I found:
Quote:
Hibernate's HQL language is not capable for handling the "inner join on" clauses. If our domain entity model includes relationships defined between the related objects then the query like this
Query query = session.createQuery("from Car car inner join Owner owner where owner.Name ='Vinod'");
will work.
Here is the query I tried in the NetBeans HQL query option:
from TbDevice dev inner join TbCustDevice cdev where dev.biDeviceId=cdev.biDeviceId and dev.tiDeviceStatusId=2 and cdev.biAccountId=33But I get the following error message and do not understand why.
Can anyone give me some insight on what I am doing wrong?
Thanks.
Error:
Code:
org.hibernate.QueryException: outer or full join must be followed by path expression [from hibernate.TbDevice dev inner join TbCustDevice cdev where dev.biDeviceId=cdev.biDeviceId and dev.tiDeviceStatusId=2 and cdev.biAccountId=33]
at org.hibernate.hql.classic.FromParser.token(FromParser.java:170)
at org.hibernate.hql.classic.ClauseParser.token(ClauseParser.java:86)
at org.hibernate.hql.classic.PreprocessingParser.token(PreprocessingParser.java:108)
at org.hibernate.hql.classic.ParserHelper.parse(ParserHelper.java:28)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:216)
at org.hibernate.hql.classic.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:185)
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)
Mapping files for:
TbDevice:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 6, 2012 5:09:07 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="ROVRDEMO" name="hibernate.TbDevice" schema="dbo" table="tbDevice">
<id name="biDeviceId" type="long">
<column name="biDeviceId"/>
<generator class="assigned"/>
</id>
<many-to-one class="hibernate.TbUser" fetch="select" name="tbUser">
<column name="iUpdUserId" not-null="true"/>
</many-to-one>
<many-to-one class="hibernate.StbDeviceStatus" fetch="select" name="stbDeviceStatus">
<column name="tiDeviceStatusId" not-null="true"/>
</many-to-one>
<property name="vcImei" type="string">
<column length="20" name="vcIMEI" not-null="true" unique="true"/>
</property>
<property name="dtStatusUpdTime" type="timestamp">
<column length="23" name="dtStatusUpdTime"/>
</property>
<property name="dtUpdDate" type="timestamp">
<column length="23" name="dtUpdDate" not-null="true"/>
</property>
<property name="sdtRetiredDate" type="timestamp">
<column length="16" name="sdtRetiredDate"/>
</property>
<property name="ipegscriptVersion" type="java.lang.Integer">
<column name="iPEGScriptVersion"/>
</property>
<property name="iconfigVersion" type="java.lang.Integer">
<column name="iConfigVersion"/>
</property>
<property name="vcLmufirmwareVersion" type="string">
<column length="3" name="vcLMUFirmwareVersion"/>
</property>
<property name="iapplicationProgramId" type="java.lang.Integer">
<column name="iApplicationProgramId"/>
</property>
<property name="vcUim" type="string">
<column length="20" name="vcUIM"/>
</property>
<property name="iuimfirmwareVersion" type="java.lang.Integer">
<column name="iUIMFirmwareVersion"/>
</property>
<set inverse="true" name="tbEventTrxns">
<key>
<column name="biDeviceId" not-null="true"/>
</key>
<one-to-many class="hibernate.TbEventTrxn"/>
</set>
<set inverse="true" name="tbCustDevices">
<key>
<column name="biDeviceId"/>
</key>
<one-to-many class="hibernate.TbCustDevice"/>
</set>
</class>
</hibernate-mapping>
TbCustDevice:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 6, 2012 5:09:07 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class catalog="ROVRDEMO" name="hibernate.TbCustDevice" schema="dbo" table="tbCustDevice">
<id name="biCustDeviceId" type="long">
<column name="biCustDeviceID"/>
<generator class="assigned"/>
</id>
<many-to-one class="hibernate.TbUser" fetch="select" name="tbUser">
<column name="iUpdUserId"/>
</many-to-one>
<many-to-one class="hibernate.TbDevice" fetch="select" name="tbDevice">
<column name="biDeviceId"/>
</many-to-one>
<many-to-one class="hibernate.StbCustDeviceStatus" fetch="select" name="stbCustDeviceStatus">
<column name="tiCustDeviceStatusId" not-null="true"/>
</many-to-one>
<many-to-one class="hibernate.TbCustVehicle" fetch="select" name="tbCustVehicle">
<column name="biCustVehicleId"/>
</many-to-one>
<many-to-one class="hibernate.TbCustAccount" fetch="select" name="tbCustAccount">
<column name="biAccountId"/>
</many-to-one>
<property name="dtStartEffTime" type="timestamp">
<column length="23" name="dtStartEffTime" not-null="true"/>
</property>
<property name="dtEndEffTime" type="timestamp">
<column length="23" name="dtEndEffTime"/>
</property>
<property name="dtUpdTime" type="timestamp">
<column length="23" name="dtUpdTime" not-null="true"/>
</property>
<property name="vcImei" type="string">
<column length="20" name="vcIMEI"/>
</property>
<property name="tiLastKnownNomination" type="java.lang.Byte">
<column name="tiLastKnownNomination"/>
</property>
<property name="dcDeviceCost" type="big_decimal">
<column name="dcDeviceCost" precision="9"/>
</property>
<property name="dtStatusUpdTime" type="timestamp">
<column length="23" name="dtStatusUpdTime" not-null="true"/>
</property>
<set inverse="true" name="tbCustDevicesSubscribeToServiceses">
<key>
<column name="biCustDeviceID" not-null="true"/>
</key>
<one-to-many class="hibernate.TbCustDevicesSubscribeToServices"/>
</set>
<set inverse="true" name="tbCustDevicesHaveServiceses">
<key>
<column name="biCustDeviceID" not-null="true"/>
</key>
<one-to-many class="hibernate.TbCustDevicesHaveServices"/>
</set>
<set inverse="true" name="tbEventTrxns">
<key>
<column name="biCustDeviceID" not-null="true"/>
</key>
<one-to-many class="hibernate.TbEventTrxn"/>
</set>
</class>
</hibernate-mapping>