-->
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: Composite-Id: session.get() doesn't retrieve Set (HQL does)
PostPosted: Mon Jan 15, 2007 12:00 pm 
Newbie

Joined: Thu Jan 11, 2007 10:55 am
Posts: 1
Location: Poland
Hello,

I'm trying to map a one-to-many relation of a Property (WxpPropData) that contains a set of Attributes (WxpPropAttributeData).
The DB schema was forced on me. Both tables have Composite-ID. The relation is mapped on a primary key - Attribute's PK consists Property's PK plus attributeId.

The problem is in retrieving data from the DB (see detailed code below):
1. When I use session.get() method to retrieve a Property - it's attributes are not retrieved.
2. I've found a workaround - When I use HQL query to retrieve a Property - it is retrieved with it's attributes - it works fine!
3. Saving a Property with session.save() does save both a property and it's attributes - works fine!

What I have already tried:
1. Changing lazy attribute to "false" doesn't help.
2. I checked with LogDriver what SQL statements are generated by Hibernate (with values) and invoked them manually. They are correct. First result contains a Property and the second one contains all it's Attributes. Up to this point everything seems fine.

Best Regards,
urulooke


Hibernate version:
Code:
Hibernate version 3.1.3.
(Hibernate version 3.2.1 GA also tried - same results)


Mapping documents:
Code:
    <class name="WxpPropData" table="HBI_AUFTRITT_EIGS">
        <composite-id name="pk" class="WxpPropPk">
            <key-property name="auftritt" column="AUFTRITT" type="string" />
            <key-property name="release" column="AUFTRITT_VERS" type="long" />
            <key-property name="propertyId" column="AUFTRITT_ID" type="string" />
            <key-property name="projectId" column="PRJK_ID" type="string" />
        </composite-id>

        <property name="type">
            <column name="EIGS_TYP" sql-type="varchar(255)" />
        </property>

        <set name="attributes" cascade="all" inverse="true" lazy="true">
            <key>
                <column name="AUFTRITT" />
                <column name="AUFTRITT_VERS" />
                <column name="AUFTRITT_ID" />
                <column name="PRJK_ID" />
            </key>
            <one-to-many class="WxpPropAttributeData" />
        </set>
    </class>

Code:
    <class name="WxpPropAttributeData" table="HBI_AUFTRITT_EIGS_ATTR">
        <composite-id name="pk" class="WxpPropAttributePk">
            <key-property name="propertyId" column="AUFTRITT_ID" type="string" />
            <key-property name="auftritt" column="AUFTRITT" type="string" />
            <key-property name="release" column="AUFTRITT_VERS" type="long" />
            <key-property name="projectId" column="PRJK_ID" type="string" />
            <key-property name="attributeId" column="ATTR_NAME" type="string" />
        </composite-id>

        <property name="value">
            <column name="ATTR_WERT" sql-type="varchar(2048)" />
        </property>       
    </class>


Code between sessionFactory.openSession() and session.close():

This part of code retrieves a property, but the attributes set is empty:
Code:
WxpPropData wxpPropData = (WxpPropData) se.get( WxpPropData.class,
   new WxpPropPk( auftritt, release, projectId, id ) );
Iterator it = wxpPropData.getAttributes().iterator();

This part of code retrieves a property along with its attributes:
Code:
String hqlQuery = "select wxp from WxpPropData as wxp" +
   " where wxp.pk.auftritt = :auftritt" +
   " and wxp.pk.release = :release" +
   " and wxp.pk.propertyId = :propertyId" +
   " and wxp.pk.projectId = :projectId";
List wxpProperties = se.createQuery(hqlQuery)
   .setString( "auftritt", auftritt )
   .setLong( "release", release )
   .setString( "propertyId", id )
   .setString( "projectId", projectId )
   .list();
WxpPropData wxpPropData = (WxpPropData) wxpProperties.get(0);


Full stack trace of any exception that occurs:
No exceptions.

Name and version of the database you are using:
IBM DB2 v8.1.12.99

The generated SQL (show_sql=true):
Code:
Hibernate: select wxppropdat0_.AUFTRITT as AUFTRITT10_1_, wxppropdat0_.AUFTRITT_VERS as AUFTRITT2_10_1_, wxppropdat0_.AUFTRITT_ID as AUFTRITT3_10_1_, wxppropdat0_.PRJK_ID as PRJK4_10_1_, wxppropdat0_.EIGS_TYP as EIGS5_10_1_, attributes1_.AUFTRITT as AUFTRITT3_, attributes1_.AUFTRITT_VERS as AUFTRITT3_3_, attributes1_.AUFTRITT_ID as AUFTRITT1_3_, attributes1_.PRJK_ID as PRJK4_3_, attributes1_.ATTR_NAME as ATTR5_3_, attributes1_.AUFTRITT_ID as AUFTRITT1_9_0_, attributes1_.AUFTRITT as AUFTRITT9_0_, attributes1_.AUFTRITT_VERS as AUFTRITT3_9_0_, attributes1_.PRJK_ID as PRJK4_9_0_, attributes1_.ATTR_NAME as ATTR5_9_0_, attributes1_.ATTR_WERT as ATTR6_9_0_ from S422.HBI_AUFTRITT_EIGS wxppropdat0_ left outer join S422.HBI_AUFTRITT_EIGS_ATTR attributes1_ on wxppropdat0_.AUFTRITT=attributes1_.AUFTRITT and wxppropdat0_.AUFTRITT_VERS=attributes1_.AUFTRITT_VERS and wxppropdat0_.AUFTRITT_ID=attributes1_.AUFTRITT_ID and wxppropdat0_.PRJK_ID=attributes1_.PRJK_ID where wxppropdat0_.AUFTRITT=? and wxppropdat0_.AUFTRITT_VERS=? and wxppropdat0_.AUFTRITT_ID=? and wxppropdat0_.PRJK_ID=?

Code:
Hibernate: select attributes0_.AUFTRITT as AUFTRITT1_, attributes0_.AUFTRITT_VERS as AUFTRITT3_1_, attributes0_.AUFTRITT_ID as AUFTRITT1_1_, attributes0_.PRJK_ID as PRJK4_1_, attributes0_.ATTR_NAME as ATTR5_1_, attributes0_.AUFTRITT_ID as AUFTRITT1_9_0_, attributes0_.AUFTRITT as AUFTRITT9_0_, attributes0_.AUFTRITT_VERS as AUFTRITT3_9_0_, attributes0_.PRJK_ID as PRJK4_9_0_, attributes0_.ATTR_NAME as ATTR5_9_0_, attributes0_.ATTR_WERT as ATTR6_9_0_ from S422.HBI_AUFTRITT_EIGS_ATTR attributes0_ where attributes0_.AUFTRITT=? and attributes0_.AUFTRITT_VERS=? and attributes0_.AUFTRITT_ID=? and attributes0_.PRJK_ID=?


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.