Hibernate custom loader query

Asked by denean

this is the mapping in my hibernate
 

<?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 = 'Сис_тип_объекта')"/>
        <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>'Сис_тип_объекта'</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>
        <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="элемент меню">
            <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="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('элемент меню', 'sysWebMenuGr') }
    </sql-query>
</hibernate-mapping>


well, MenuItem is loaded for some reason with a standard query, and not at all by calling SphObjects.selectMenuItemObjects, which by the way works fine if manually called. Who knows why? at the office. the forum is silent ...

Database Designer, with good visualization and work with the database? :: Advise a good book (books) on the design of software architecture. Beginner-intermediate level :: What are the analogues of OpenX? :: Who will be the first to place their data centers on the moon? :: Redirect depending on User Agent by means of Apache
Leave Repply for Hibernate custom loader query
Useful Links