-->
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: unwanted eager loading
PostPosted: Mon Feb 14, 2005 8:50 pm 
Newbie

Joined: Mon Dec 27, 2004 10:23 am
Posts: 7
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1.7c

I get the following error when attempting to load the groups of a user using user.getGroups(). I suspect this is due to the bizarre generated sql that is shown below. One can see that the usermetadata table/class is involved. however, User hasn't got any properties involving Metadata, whereas the inverse is true. Only, we are using the User class, not the Metadata class...

2005-02-15 00:53:52,115 ERROR [net.sf.hibernate.LazyInitializationException] - <Failed to lazily initialize a collection - no session or session was closed>

What can I do ?

bernard

generated SQL:



Code:
Hibernate: select userimpl4_.ID as ID, userimpl4_.USERNAME as USERNAME, userimpl4_.PASSWORD as PASSWORD, userimpl4_.PERSON_FK as PERSON_FK, userimpl4_.THUMBNAIL_FK as THUMBNAI5_, userimpl4_.CALENDAR_FK as CALENDAR6_ from APPLICATION applicatio0_ left outer join APPLICATIONS_GROUPS groups1_ on applicatio0_.ID=groups1_.APPLICATIONS_FK left outer join USER_GROUP usergroupi2_ on groups1_.GROUPS_FK=usergroupi2_.ID inner join GROUPS_HAVE_USERS users3_ on usergroupi2_.ID=users3_.GROUPS_FK inner join USER userimpl4_ on users3_.USERS_FK=userimpl4_.ID where (applicatio0_.NAME=? )AND(userimpl4_.USERNAME=? )AND(userimpl4_.PASSWORD=? )

Hibernate: select usermetada0_.ID as ID10_, usermetada0_.class as class10_, usermetada0_.PREDICATE_FK as PREDICAT3_10_, usermetada0_.USER_FK as USER_FK10_, usermetada0_.POSITION_FK as POSITION5_10_, predicatei1_.ID as ID0_, predicatei1_.URI as URI0_, predicatei1_.CORE_PREDICATE as CORE_PR32_0_, predicatei1_.OBJECT_FK as OBJECT_FK0_, predicatei1_.DESCRIPTION_FK as DESCRIP34_0_, predicatei1_.CORE_M_D_FK as CORE_M_D3_0_, abstractob2_.ID as ID1_, abstractob2_.class as class1_, abstractob2_.PREDICATE_FK as PREDICAT4_1_, abstractob2_.CORE_M_D_FK as CORE_M_D3_1_, abstractob2_.MEDIA_PATH as MEDIA_PATH1_, abstractob2_.ORIGINAL_MEDIA_PATH as ORIGINAL6_1_, abstractob2_.MEDIA_U_R_L as MEDIA_U_7_1_, abstractob2_.IS_REMOTE as IS_REMOTE1_, abstractob2_.TEXT as TEXT1_, abstractob2_.URI as URI1_, abstractob2_.STRING_VALUE as STRING_11_1_, abstractob2_.BOOLEAN_VALUE as BOOLEAN12_1_, abstractob2_.FLOAT_VALUE as FLOAT_V13_1_, abstractob2_.INT_VALUE as INT_VALUE1_, abstractob2_.DATE_VALUE as DATE_VALUE1_, abstractob2_.VALUE_TYPE as VALUE_TYPE1_, abstractob2_.PLACE_FK as PLACE_FK1_, abstractob2_.TIME_INFO_FK as TIME_IN18_1_, abstractob2_.RECURRING_EVENT_FK as RECURRI19_1_, abstractob2_.FIRSTNAME as FIRSTNAME1_, abstractob2_.LASTNAME as LASTNAME1_, abstractob2_.BIRTHDATE as BIRTHDATE1_, abstractob2_.TIMESTAMP as TIMESTAMP1_, abstractob2_.MIDDLE_NAME as MIDDLE_24_1_, abstractob2_.ADDRESS_FK as ADDRESS_FK1_, abstractob2_.LOCATION_FK as LOCATIO26_1_, abstractob2_.ORGANIZATION_FK as ORGANIZ27_1_, abstractob2_.TRACKS_FK as TRACKS_FK1_, abstractob2_.SUPER_ACTIVITY_FK as SUPER_A29_1_, abstractob2_.PERSON_FK as PERSON_FK1_, abstractob2_.ACTIVITY_FK as ACTIVIT31_1_, labelimpl3_.ID as ID2_, coremetada4_.ID as ID3_, coremetada4_.TYPE as TYPE3_, coremetada4_.LANGUAGE as LANGUAGE3_, coremetada4_.DATE_FK as DATE_FK3_, coremetada4_.TEMPORAL_COVERAGE_FK as TEMPORAL5_3_, coremetada4_.IDENTIFIER_FK as IDENTIFI6_3_, coremetada4_.PUBLISHER_FK as PUBLISHE7_3_, coremetada4_.CREATOR_FK as CREATOR_FK3_, userimpl5_.ID as ID4_, userimpl5_.USERNAME as USERNAME4_, userimpl5_.PASSWORD as PASSWORD4_, userimpl5_.PERSON_FK as PERSON_FK4_, userimpl5_.THUMBNAIL_FK as THUMBNAI5_4_, userimpl5_.CALENDAR_FK as CALENDAR6_4_, personimpl6_.ID as ID5_, personimpl6_.FIRSTNAME as FIRSTNAME5_, personimpl6_.LASTNAME as LASTNAME5_, personimpl6_.BIRTHDATE as BIRTHDATE5_, personimpl6_.TIMESTAMP as TIMESTAMP5_, personimpl6_.MIDDLE_NAME as MIDDLE_24_5_, personimpl6_.PREDICATE_FK as PREDICAT4_5_, personimpl6_.CORE_M_D_FK as CORE_M_D3_5_, imageimpl7_.ID as ID6_, imageimpl7_.MEDIA_PATH as MEDIA_PATH6_, imageimpl7_.ORIGINAL_MEDIA_PATH as ORIGINAL6_6_, imageimpl7_.MEDIA_U_R_L as MEDIA_U_7_6_, imageimpl7_.IS_REMOTE as IS_REMOTE6_, imageimpl7_.PREDICATE_FK as PREDICAT4_6_, imageimpl7_.CORE_M_D_FK as CORE_M_D3_6_, calendarim8_.ID as ID7_, calendarim8_.CORE_M_D_FK as CORE_M_D3_7_, positionim9_.ID as ID8_, positionim9_.START_TIME as START_TIME8_, positionim9_.END_TIME as END_TIME8_, positionim9_.SHAPE_FK as SHAPE_FK8_, shapeimpl10_.ID as ID9_, shapeimpl10_.class as class9_, shapeimpl10_.FILL_COLOR as FILL_COLOR9_, shapeimpl10_.LINE_COLOR as LINE_COLOR9_, shapeimpl10_.LINE_THICKNESS as LINE_THI5_9_, shapeimpl10_._X as _X9_, shapeimpl10_._Y as _Y9_, shapeimpl10_._WIDTH as _WIDTH9_, shapeimpl10_._HEIGHT as _HEIGHT9_, shapeimpl10_.CENTER_X as CENTER_X9_, shapeimpl10_.CENTER_Y as CENTER_Y9_, shapeimpl10_.RADIUS as RADIUS9_ from USER_METADATA usermetada0_ left outer join RESOURCE predicatei1_ on usermetada0_.PREDICATE_FK=predicatei1_.ID left outer join RESOURCE abstractob2_ on predicatei1_.OBJECT_FK=abstractob2_.ID left outer join LABEL labelimpl3_ on predicatei1_.DESCRIPTION_FK=labelimpl3_.ID left outer join CORE_METADATA coremetada4_ on predicatei1_.CORE_M_D_FK=coremetada4_.ID left outer join USER userimpl5_ on usermetada0_.USER_FK=userimpl5_.ID left outer join RESOURCE personimpl6_ on userimpl5_.PERSON_FK=personimpl6_.ID left outer join RESOURCE imageimpl7_ on userimpl5_.THUMBNAIL_FK=imageimpl7_.ID left outer join RESOURCE calendarim8_ on userimpl5_.CALENDAR_FK=calendarim8_.ID left outer join POSITION positionim9_ on usermetada0_.POSITION_FK=positionim9_.ID left outer join SHAPE shapeimpl10_ on positionim9_.SHAPE_FK=shapeimpl10_.ID where usermetada0_.USER_FK=?



mapping files

UserMetadata

Code:
<hibernate-mapping default-cascade="none">
    <class name="fractals.psychos.core.metadata.dc.entity.UserMetadataImpl" table="USER_METADATA">
        <id name="id" type="java.lang.Long" column="ID" unsaved-value="null">
            <generator class="native">
            </generator>
        </id>
        <discriminator column="class" type="string"/>
        <set name="relations" order-by="MORE_TERMS_FK" lazy="false" outer-join="auto" inverse="false" cascade="delete">
            <key>
                <column name="MORE_TERMS_FK"/>
            </key>
            <one-to-many class="fractals.psychos.core.metadata.dc.entity.RelationTermImpl"/>
        </set>
        <many-to-one name="predicate" class="fractals.psychos.core.metadata.entity.PredicateImpl" outer-join="auto" unique="true" not-null="false">
            <column name="PREDICATE_FK"/>
        </many-to-one>
        <many-to-one name="user" class="fractals.psychos.core.system.entity.UserImpl" outer-join="auto" unique="true" not-null="false">
            <column name="USER_FK"/>
        </many-to-one>

        <subclass name="fractals.psychos.core.media.entity.VideoReferenceImpl" discriminator-value="VideoReferenceImpl">
        <many-to-one name="position" class="fractals.psychos.core.media.entity.PositionImpl" outer-join="auto" unique="true" cascade="delete" not-null="false">
            <column name="POSITION_FK"/>
        </many-to-one>

        </subclass>
    </class>
</hibernate-mapping>


User

Code:
<hibernate-mapping default-cascade="none">
    <class name="fractals.psychos.core.system.entity.UserImpl" table="USER">
        <id name="id" type="java.lang.Long" column="ID" unsaved-value="null">
            <generator class="native">
            </generator>
        </id>
        <property name="username" type="java.lang.String">
            <column name="USERNAME" not-null="false" unique="false" sql-type="VARCHAR(255) BINARY"/>
        </property>
        <property name="password" type="java.lang.String">
            <column name="PASSWORD" not-null="false" unique="false" sql-type="VARCHAR(255) BINARY"/>
        </property>
        <set name="groups" table="GROUPS_HAVE_USERS" order-by="GROUPS_FK" outer-join="auto" lazy="true" inverse="false">
            <key>
                <column name="USERS_FK"/>
            </key>
            <many-to-many class="fractals.psychos.core.system.entity.UserGroupImpl" column="GROUPS_FK"/>
        </set>
        <set name="predicates" table="USERS_DEFINE_PREDICATES" order-by="PREDICATES_FK" outer-join="auto" lazy="true" inverse="false">
            <key>
                <column name="USERS_FK"/>
            </key>
            <many-to-many class="fractals.psychos.core.metadata.entity.PredicateImpl" column="PREDICATES_FK"/>
        </set>
        <set name="properties" order-by="USER_FK" lazy="true" outer-join="auto" inverse="false" cascade="delete">
            <key>
                <column name="USER_FK"/>
            </key>
            <one-to-many class="fractals.psychos.core.metadata.entity.PropertyImpl"/>
        </set>
        <many-to-one name="person" class="fractals.psychos.core.ontology.entity.PersonImpl" outer-join="auto" unique="true" cascade="delete" not-null="false">
            <column name="PERSON_FK"/>
        </many-to-one>
        <many-to-one name="thumbnail" class="fractals.psychos.core.media.entity.ImageImpl" outer-join="auto" unique="true" cascade="delete" not-null="false">
            <column name="THUMBNAIL_FK"/>
        </many-to-one>
        <set name="myGroups" order-by="USER_FK" lazy="true" outer-join="auto" inverse="false" cascade="delete">
            <key>
                <column name="USER_FK"/>
            </key>
            <one-to-many class="fractals.psychos.core.system.entity.UserGroupImpl"/>
        </set>
        <set name="accounts" order-by="USER_FK" lazy="true" outer-join="auto" inverse="false" cascade="delete">
            <key>
                <column name="USER_FK"/>
            </key>
            <one-to-many class="fractals.psychos.core.system.entity.AccountImpl"/>
        </set>
        <one-to-one name="metadata" class="fractals.psychos.core.metadata.dc.entity.UserMetadataImpl" outer-join="auto" property-ref="user"/>
        <many-to-one name="calendar" class="fractals.psychos.core.pim.entity.CalendarImpl" outer-join="auto" unique="true" cascade="delete" not-null="false">
            <column name="CALENDAR_FK"/>
        </many-to-one>

    </class>
</hibernate-mapping>


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.