-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Please help! Problem in query (joins)
PostPosted: Tue Jan 13, 2004 7:09 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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)
-----------------------------------------
MpLote
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.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>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
join ml.armazemMp,

missing an alias here


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:47 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
gloeglm wrote:
join ml.armazemMp,

missing an alias here


Sorry. Didn't work. Gives me the same error even with:
Code:
( ... )
res = session.find("select ml, ms " +
         "from pt.comseal.arsol.vo.MpLote as ml join ml.mp as mp join ml.armazemMp as am, " +
         "pt.comseal.arsol.vo.MpStocks as ms " +
         "where mp.id = ms.mp.id and mp.referencia like upper('%" + ref_padrao + "%') order by ml.referencia asc");
( ... )



Any ideas please?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 8:38 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
nerotnt wrote:
gloeglm wrote:
join ml.armazemMp,

missing an alias here


Thanks for the reply.
I've found the error:
Code:
( ... )
res = session.find("select ml, ms " +
         "from pt.comseal.arsol.vo.MpLote as ml join ml.mp as mp join ml.armazemMp as am, " +
         "mp.MpStocks as ms " +
         "where mp.id = ms.mp.id and mp.referencia like upper('%" + ref + "%') order by ml.referencia asc");
( ... )


I should have used the alias for mp.MpStocks as ms.


Thanks again gloeglm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.