-->
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.  [ 7 posts ] 
Author Message
 Post subject: lazy="false" not work on many-to-one
PostPosted: Fri Sep 09, 2005 5:16 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
I set lazy="false" on the many-to-one element yet after I close the session I a getting a proxy exception. any ideas?

Thanks for any suggestions
J

Hibernate version:
3.1

Mapping documents:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
    <class name="com.volant.vini.model.VsiCounty" table="vsi_county" catalog="vini">
        <composite-id name="id" class="com.volant.vini.model.VsiCountyId">
            <key-property name="countyCode" type="string">
                <column name="COUNTY_CODE" length="3" />
            </key-property>
            <key-property name="stateCode" type="string">
                <column name="STATE_CODE" length="2" />
            </key-property>
        </composite-id>
        <many-to-one name="vsiState" class="com.volant.vini.model.VsiState" lazy="false" update="false" insert="false">
            <column name="STATE_CODE" length="2" not-null="true" />
        </many-to-one>
        <property name="countyName" type="string">
            <column name="COUNTY_NAME" length="50" />
        </property>
    </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
      VsiCounty county = (VsiCounty) ViniSessionFactory.currentSession()
            .load(VsiCounty.class, new VsiCountyId("42", "001"));
      ViniSessionFactory.closeSession();
      assertNotNull("state is null", county.getVsiState());

Full stack trace of any exception that occurs:

Code:
ERROR [main] (LazyInitializationException.java:19) - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:54)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:85)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:131)
   at com.volant.vini.model.VsiCounty$$EnhancerByCGLIB$$593f1e55.getVsiState(<generated>)
   at com.volant.vini.test.db.TestViniDAO.testNoneLazyState(TestViniDAO.java:96)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Name and version of the database you are using:
Oracle 10 g
The generated SQL (show_sql=true):
na
Debug level Hibernate log excerpt:
na


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 10:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Remove the proxy/lazy setting from the com.volant.vini.model.VsiState mapping. Lasy="false" in your many-to-one will not do what your trying to do.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 5:04 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
tried this with VsiState...

Code:
   <class name="com.volant.vini.model.VsiCounty" table="vsi_county" catalog="vini">
        <composite-id name="id" class="com.volant.vini.model.VsiCountyId">
            <key-property name="countyCode" type="string">
                <column name="COUNTY_CODE" length="3" />
            </key-property>
            <key-property name="stateCode" type="string">
                <column name="STATE_CODE" length="2" />
            </key-property>
        </composite-id>
        <many-to-one name="vsiState" class="com.volant.vini.model.VsiState" lazy="false" update="false" insert="false">
            <column name="STATE_CODE" length="2" not-null="true" />
        </many-to-one>
        <property name="countyName" type="string">
            <column name="COUNTY_NAME" length="50" />
        </property>
    </class>



I even teid setting lazy="true", in both cases the code is throwing the exception.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 5:15 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
copied over the wrong version of the configuration file...

Code:
<class name="com.volant.vini.model.VsiCounty" table="vsi_county" catalog="vini">
        <composite-id name="id" class="com.volant.vini.model.VsiCountyId">
            <key-property name="countyCode" type="string">
                <column name="COUNTY_CODE" length="3" />
            </key-property>
            <key-property name="stateCode" type="string">
                <column name="STATE_CODE" length="2" />
            </key-property>
        </composite-id>
        <many-to-one name="vsiState" class="com.volant.vini.model.VsiState" lazy="true" update="false" insert="false">
            <column name="STATE_CODE" length="2" not-null="true" />
        </many-to-one>
        <property name="countyName" type="string">
            <column name="COUNTY_NAME" length="50" />


also tried the default proxy setting but eh previous code still throws the LaztInitializationException. Is it possible to do egar loading on both sides of the asscoiation?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 5:15 pm 
Regular
Regular

Joined: Thu Sep 23, 2004 11:53 am
Posts: 83
copied over the wrong version of the configuration file...

Code:
<class name="com.volant.vini.model.VsiCounty" table="vsi_county" catalog="vini">
        <composite-id name="id" class="com.volant.vini.model.VsiCountyId">
            <key-property name="countyCode" type="string">
                <column name="COUNTY_CODE" length="3" />
            </key-property>
            <key-property name="stateCode" type="string">
                <column name="STATE_CODE" length="2" />
            </key-property>
        </composite-id>
        <many-to-one name="vsiState" class="com.volant.vini.model.VsiState" lazy="true" update="false" insert="false">
            <column name="STATE_CODE" length="2" not-null="true" />
        </many-to-one>
        <property name="countyName" type="string">
            <column name="COUNTY_NAME" length="50" />


also tried the default proxy setting but the previous code still throws the LaztInitializationException. Is it possible to do egar loading on both sides of the asscoiation?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 8:28 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
H2 - the class level proxy needs to be defined true (or proxy class set).
H3 - the default changed so class level lazy is true unless otherwised defined.

So, in your class mapping for the VsiCounty class use the following

Code:
<class name="com.volant.vini.model.VsiCounty" table="vsi_county" catalog="vini" lazy="false">
...

The lazy setting on the many-to-one is used in a different mode (field level lazy loading) so I suggest you delete the lazy attibute on the many-to-one.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 16, 2006 7:05 pm 
Newbie

Joined: Tue Nov 07, 2006 5:06 pm
Posts: 13
Why is this? This seems contrary to everything I've read about lazy-loading and the lazy attribute.


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