-->
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.  [ 3 posts ] 
Author Message
 Post subject: Subclass query loader
PostPosted: Thu Sep 02, 2010 5:19 am 
Newbie

Joined: Thu Sep 02, 2010 5:02 am
Posts: 1
Hi, this is my mapping:
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">
<hibernate-mapping>
    <class name="hibernate.entities.SphObjects" schema="SPH_DEV" table="SPH_OBJECTS">
        <id name="objectId" type="int">
            <column name="OBJECT_ID" precision="5" scale="0"/>
            <generator class="assigned"/>
        </id>
        <discriminator column="OBJECT_TYPE" type="string" insert="false" formula="(select ulist_value from user_list_values where ulist_code = 'sys_obj_type')"/>
        <many-to-one class="hibernate.entities.Modules" fetch="select" name="modules">
            <column length="6" name="MODULE_CODE" not-null="true"/>
        </many-to-one>
        <many-to-one class="hibernate.entities.UserListValues" fetch="select" name="objectType">
            <formula>'sys_obj_type'</formula>
            <column name="OBJECT_TYPE" not-null="true" precision="5" scale="0"/>
        </many-to-one>
        <many-to-one class="hibernate.entities.SphObjects" fetch="select" name="sphObjects">
            <column name="PARENT_ID" precision="5" scale="0"/>
        </many-to-one>
        <property name="code" type="string">
            <column length="16" name="CODE" not-null="true"/>
        </property>
        <property name="name" type="string">
            <column length="64" name="NAME" not-null="true"/>
        </property>
        <property name="argCount" type="big_decimal">
            <column name="ARG_COUNT" precision="22" scale="0"/>
        </property>
        <property name="objectBody" type="clob">
            <column name="OBJECT_BODY"/>
        </property>
        <property name="objectArgs" type="clob">
            <column name="OBJECT_ARGS"/>
        </property>
        <property name="note" type="string">
            <column length="256" name="NOTE"/>
        </property>
        <set inverse="true" name="sphRoleses" table="ROLE_OBJECTS">
            <key>
                <column name="OBJECT_ID" not-null="true" precision="5" scale="0"/>
            </key>
            <many-to-many entity-name="hibernate.entities.SphRoles">
                <column name="ROLE_ID" not-null="true" precision="5" scale="0"/>
            </many-to-many>
        </set>
        <set cascade="all" inverse="true" name="sphObjectses">
            <key>
                <column name="PARENT_ID" precision="5" scale="0"/>
            </key>
            <one-to-many class="hibernate.entities.SphObjects"/>
        </set>

        <subclass name="hibernate.entities.MenuItem" discriminator-value="menu element">
            <property name="label" type="string">
                <column length="256" name="LABEL"/>
            </property>
            <property name="order" type="int">
                <column name="IORDER"/>
            </property>
            <loader query-ref="SphObjects.selectMenuItemObjects"/>
        </subclass>
       
       
    </class>

    <sql-query name="SphObjects.selectMenuItemObjects" callable="true">
        <return alias="MenuItem" class="hibernate.entities.MenuItem">
            <return-property name="objectId" column="OBJECT_ID"/>
            <return-property name="code" column="CODE"/>
            <return-property name="name" column="NAME"/>
            <return-property name="argCount" column="ARG_COUNT"/>
            <return-property name="objectBody" column="OBJECT_BODY"/>
            <return-property name="objectArgs" column="OBJECT_ARGS"/>
            <return-property name="note" column="NOTE"/>
            <return-property name="label" column="LABEL"/>
            <return-property name="order" column="ORDER"/>
            <return-property name="modules" column="MODULE_CODE"/>
            <return-property name="sphObjects" column="PARENT_ID"/>
            <return-property name="objectType">
                <return-column name="ULIST_CODE"/>
                <return-column name="OBJECT_TYPE"/>
            </return-property>
        </return>
        { ? = call sph_objects_api.get_flexed_objects('menu element', 'sysWebMenuGr') }
    </sql-query>
</hibernate-mapping>


code for loading entities:
Code:
Criteria crit = getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(hibernate.entities.MenuItem.class);
return crit.list();


but entities not loading by loader query-ref. they're loading by standart query:
Code:
Hibernate:
    select
        this_.OBJECT_ID as OBJECT1_0_0_,
        this_.MODULE_CODE as MODULE2_0_0_,
        this_.OBJECT_TYPE as OBJECT3_0_0_,
        this_.PARENT_ID as PARENT4_0_0_,
        this_.CODE as CODE0_0_,
        this_.NAME as NAME0_0_,
        this_.ARG_COUNT as ARG7_0_0_,
        this_.OBJECT_BODY as OBJECT8_0_0_,
        this_.OBJECT_ARGS as OBJECT9_0_0_,
        this_.NOTE as NOTE0_0_,
        this_.LABEL as LABEL0_0_,
        this_.IORDER as IORDER0_0_,
        'sys_obj_type' as formula1_0_
    from
        SPH_DEV.SPH_OBJECTS this_
    where
        (
            select
                this_.ulist_value
            from
                user_list_values
            where
                this_.ulist_code = 'sys_obj_type'
        )='menu element'


why they're not loading by loader query?

p.s.
the named query works fine.
Code
Code:
final Query namedQuery = getHibernateTemplate().getSessionFactory().getCurrentSession().getNamedQuery("SphObjects.selectMenuItemObjects");
List l = namedQuery.list();
return l;

works without errors.


Top
 Profile  
 
 Post subject: Re: Subclass query loader
PostPosted: Tue Mar 22, 2011 5:08 am 
Newbie

Joined: Tue Mar 22, 2011 5:06 am
Posts: 1
I have the same problem


Top
 Profile  
 
 Post subject: Re: Subclass query loader
PostPosted: Sun Dec 30, 2012 10:05 pm 
Newbie

Joined: Fri Dec 21, 2012 1:28 am
Posts: 1
Use this before return
<load-collection alias="a_alias" role="package.class.collectionPropertyName" />

The documentation is confusing.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.