-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate join query between two tables and one itself
PostPosted: Sat Nov 10, 2012 2:54 pm 
Newbie

Joined: Mon Jul 04, 2011 7:10 am
Posts: 9
Could somebody help me to construct the query I need?

With all my tries I get a "Path expected for join" error message.

I have two tables: Areas and AreasLocal. The first is structured as a tree table.

With the next query, I am able to get the whole areas tree (eagerly and with a fetch strategy).

Code:
Query query = this.sessionFactory.getCurrentSession().createQuery(
    "from Areas areas" +                       
    " left join fetch areas.childs childs" +
    " where areas.parent.idArea = 1");


BUT, I don't know how can I get the areas names, which resides in the AreasLocal table (which acts as a i18n repository).

Code:
<hibernate-mapping>
    <class name="somepaq.Areas" table="areas">

        <id name="idArea" type="java.lang.Integer">
            <column name="ID_AREA" />
        </id>

        <many-to-one name="parent" class="somepaq.Areas" fetch="select">
            <column name="ID_PADRE"/>
        </many-to-one>

        <set name="childs" table="areas" inverse="true" lazy="false" fetch="select">
            <key>
                <column name="ID_PADRE"/>
            </key>
            <one-to-many class="somepaq.Areas" />
        </set>               

    </class>
</hibernate-mapping>



Code:
<hibernate-mapping>
    <class name="somepaq.AreasLocal" table="areas_local">

        <composite-id name="id" class="somepaq.AreasLocalId">
            <key-property name="idArea" type="java.lang.Integer">
                <column name="ID_AREA" />
            </key-property>
            <key-property name="idLocal" type="java.lang.Integer">
                <column name="ID_LOCAL" />
            </key-property>
        </composite-id>

        <property name="name" type="string">
            <column name="NAME" not-null="true" />
        </property>

    </class>
</hibernate-mapping>


Thanks a lot.


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

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.