-->
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: fetch doesn't work as expected
PostPosted: Fri Aug 27, 2004 7:08 am 
Newbie

Joined: Wed Jul 14, 2004 2:51 am
Posts: 1
Hello,

The main problem refers to data returned by HQL query. U use join fetch to lazy initialized sub-class. Returned list of Attribute objects contains properly initialized data. But AttributeValue objects that are lazy initialized are not fully initialized - all AttributeValues are OK, except the first object - it still holds proxy value.

[0] Attribute.attributeValue -> proxy!!!
[1] Attribute.attributeValue -> OK
[2] Attribute.attributeValue -> OK
.... -> OK


Hibernate version:

2.1.5

Mapping documents:

<class name="Attribute" table="ATTRIBUTE">
<id name="id" type="int" column="ID">
<generator class="native" />
</id>
<property name="version" type="int" column="VERSION" length="10" />
<property name="state" type="java.lang.String" column="STATE" not-null="true" length="1" />
<property name="firstAssignedId" type="int" column="FIRST_ASSIGNED_ID" length="10" />
<!-- associations -->
<many-to-one name="parentAttribute" class="Attribute" column="PARENT_ATTRIB_ID" cascade="none" not-null="false" outer-join="true" />
<many-to-one name="attributeValue" class="AttributeValue" not-null="true" cascade="delete">
<column name="VALUE_ID" />
</many-to-one>
</class>

<hibernate-mapping package="de.systemagmbh.stationsdbWWW.DataModel">
<class name="AttributeValue" table="REF_ATTR_VALUE" lazy="true">
<meta attribute="class-description" >
Attribute value base class. Its generalization provides values of all supported types.
</meta>
<id name="id" type="int" column="ID" >
<generator class="native" />
</id>
<property name="valueType" column="VALUETYPE" type="java.lang.String" length="1" />

<joined-subclass name="BlobValue" table="BLOBVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides {@link java.sql.Blob} value.
</meta>
<key column="VALUE_ID"/>
<property name="blobvalue" type="binary" column="BLOBVALUE"
length="2147483647" />
</joined-subclass>
<joined-subclass name="BoolValue" table="BOOLVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides {@link java.lang.Boolean} value.
</meta>
<key column="VALUE_ID"/>
<property name="boolvalue" type="boolean" column="BOOLVALUE" length="1" />
</joined-subclass>
<joined-subclass name="CalcValue" table="CALCVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides calculated value based on SQL expression.
</meta>
<key column="VALUE_ID"/>
<property name="sqlexpression" type="java.lang.String" column="SQLEXPRESSION"
length="1000" />
</joined-subclass>
<joined-subclass name="FloatValue" table="FLOATVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides {@link java.lang.Double} value.
</meta>
<key column="VALUE_ID"/>
<property name="floatvalue" type="float" column="FLOATVALUE" length="10" />
</joined-subclass>
<joined-subclass name="IntValue" table="INTVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides {@link java.lang.Long} value.
</meta>
<key column="VALUE_ID"/>
<property name="intvalue" type="int" column="INTVALUE" length="10" />
</joined-subclass>
<joined-subclass name="ListValue" table="LISTVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides value based on selected list index or indices.
</meta>

<key column="VALUE_ID" />
<property name="listName" type="string" column="LIST_NAME" length="50" />
<property name="listtype" type="string" column="LISTTYPE" length="1" />
<property name="listId" column="ID" type="int" insert="false" update="false" />

<set name="listValuesStandard" inverse="true" sort="natural" order-by="LIST_ID">
<key column="LIST_ID" foreign-key="ID"/>
<one-to-many class="ListValuesStandard" />
</set>

<set name="listValuesSelect" inverse="true" sort="natural" order-by="SEL_LIST_ID">
<key column="SEL_LIST_VALUE" foreign-key="SEL_LIST_ID"/>
<one-to-many class="ListValuesSelect" />
</set>

</joined-subclass>
<joined-subclass name="StringValue" table="STRINGVALUE" lazy="true">
<meta attribute="class-description">
AttrValue extension. Provides {@link java.lang.String} value.
</meta>
<key column="VALUE_ID"/>
<property name="stringvalue" type="java.lang.String" column="STRINGVALUE" length="250" />
</joined-subclass>
</class>


<query name="AllAttributesByFirstAssignedId">
<![CDATA[from Attribute attr
join fetch attr.attributeValue
where attr.firstAssignedId=?
order by attr.date]]>
</query>

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

session.findByNamedQuery( "AllAttributesByFirstAssignedId", new Integer(1));

Full stack trace of any exception that occurs:

I don't have now, but lazy initialization error occures since returned attribute value wasn't fetched.

Name and version of the database you are using:

Microsoft SQL Server 2000

Debug level Hibernate log excerpt:


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.