I'm having problems doing the following query:
Code:
( ... )
res = session.find("select ml, ms " +
"from pt.comseal.arsol.vo.MpLote as ml join ml.mp as mp join ml.armazemMp, " +
"pt.comseal.arsol.vo.MpStocks as ms " +
"where mp.id = ms.mp.id and mp.referencia like upper('%" + ref + "%') order by ml.referencia asc");
( ... )
In resume, I want to join
MpLote with
Mp and
ArmazemMp and then join
MpStocks with
Mp (which was joined before with
MpLote).
I don't know what's the problem. I'm doing this by the documentation.
Please help.
It keeps giving me the following error:
Code:
net.sf.hibernate.QueryException: undefined alias: pt [select ml from pt.comseal.arsol.vo.MpLote as ml join ml.mp as mp join ml.armazemMp, pt.comseal.arsol.vo.MpStocks as ms where mp.id = ms.mp.id and mp.referencia like upper('%refmp1%') order by ml.referencia asc]
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:103)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.FromParser.token(FromParser.java:193)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
( ... )
-----------------------------------------
Mapping files (generated with R3)
-----------------------------------------
MpLoteCode:
<?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 Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="pt.comseal.arsol.vo.MpLote"
table="mp_lote"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Mp -->
<many-to-one
name="mp"
class="pt.comseal.arsol.vo.Mp"
not-null="true"
>
<column name="mp_fk" />
</many-to-one>
<!-- bi-directional one-to-one association to ArmazemMp -->
<one-to-one
name="armazemMp"
class="pt.comseal.arsol.vo.ArmazemMp"
outer-join="auto"
constrained="false"
/>
</class>
</hibernate-mapping>
Mp Code:
<?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 Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="pt.comseal.arsol.vo.Mp"
table="mp"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to MpLote -->
<set
name="mpLotes"
lazy="true"
inverse="true"
>
<key>
<column name="mp_fk" />
</key>
<one-to-many
class="pt.comseal.arsol.vo.MpLote"
/>
</set>
<!-- bi-directional one-to-many association to MpStock -->
<set
name="mpStocks"
lazy="true"
inverse="true"
>
<key>
<column name="mp_fk" />
</key>
<one-to-many
class="pt.comseal.arsol.vo.MpStock"
/>
</set>
</class>
</hibernate-mapping>