-->
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.  [ 2 posts ] 
Author Message
 Post subject: Session.load() for classes marked lazy
PostPosted: Mon Sep 06, 2004 8:46 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Hibernate version: 2.1.4

Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping package="model">
    <class name="Address" table="ADDRESS" proxy="Address" lazy="true">

        <id name="id" column="ADDRESS_ID" type="int">
            <generator class="increment"/>
        </id>

        <property name="street" column="STREEt"/>
        <property name="city" column="CITY"/>
    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
Address a1 = (Address) session.load(Address.class, new Integer(1));
System.out.println("Loaded Address[" + a1.getId() +"]");
a1.getCity();


Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i

Debug level Hibernate log excerpt:
Code:
2004-09-06 18:17:37,796,INFO,[main],[net.sf.hibernate.cfg.Environment],Hibernate 2.1.4
2004-09-06 18:17:37,796,INFO,[main],[net.sf.hibernate.cfg.Environment],hibernate.properties not found
2004-09-06 18:17:37,811,INFO,[main],[net.sf.hibernate.cfg.Environment],using CGLIB reflection optimizer
2004-09-06 18:17:37,811,INFO,[main],[net.sf.hibernate.cfg.Configuration],configuring from file: hibernate.cfg.xml
2004-09-06 18:17:37,999,INFO,[main],[net.sf.hibernate.cfg.Configuration],Mapping resource: model/User.hbm.xml
2004-09-06 18:17:38,124,INFO,[main],[net.sf.hibernate.cfg.Binder],Mapping class: model.User -> LUSER
2004-09-06 18:17:38,218,INFO,[main],[net.sf.hibernate.cfg.Configuration],Mapping resource: model/Address.hbm.xml
2004-09-06 18:17:38,265,INFO,[main],[net.sf.hibernate.cfg.Binder],Mapping class: model.Address -> ADDRESS
2004-09-06 18:17:38,265,INFO,[main],[net.sf.hibernate.cfg.Configuration],Configured SessionFactory: null
2004-09-06 18:17:38,265,INFO,[main],[net.sf.hibernate.cfg.Configuration],processing one-to-many association mappings
2004-09-06 18:17:38,265,INFO,[main],[net.sf.hibernate.cfg.Configuration],processing one-to-one association property references
2004-09-06 18:17:38,265,INFO,[main],[net.sf.hibernate.cfg.Configuration],processing foreign key constraints
2004-09-06 18:17:38,296,INFO,[main],[net.sf.hibernate.dialect.Dialect],Using dialect: net.sf.hibernate.dialect.OracleDialect
2004-09-06 18:17:38,296,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],Use outer join fetching: true
2004-09-06 18:17:38,296,INFO,[main],[net.sf.hibernate.connection.DriverManagerConnectionProvider],Using Hibernate built-in connection pool (not for production use!)
2004-09-06 18:17:38,311,INFO,[main],[net.sf.hibernate.connection.DriverManagerConnectionProvider],Hibernate connection pool size: 20
2004-09-06 18:17:38,311,INFO,[main],[net.sf.hibernate.connection.DriverManagerConnectionProvider],using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:oci8:@INFPRF01
2004-09-06 18:17:38,311,INFO,[main],[net.sf.hibernate.connection.DriverManagerConnectionProvider],connection properties: {user=infra_persist, password=persistence}
2004-09-06 18:17:38,311,INFO,[main],[net.sf.hibernate.transaction.TransactionManagerLookupFactory],No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],Use scrollable result sets: true
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],Use JDBC3 getGeneratedKeys(): false
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],Optimize cache for minimal puts: false
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],echoing all SQL to stdout
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],Query language substitutions: {}
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.SettingsFactory],cache provider: net.sf.ehcache.hibernate.Provider
2004-09-06 18:17:38,718,INFO,[main],[net.sf.hibernate.cfg.Configuration],instantiating and configuring caches
2004-09-06 18:17:38,874,INFO,[main],[net.sf.hibernate.impl.SessionFactoryImpl],building session factory
2004-09-06 18:17:39,405,INFO,[main],[net.sf.hibernate.impl.SessionFactoryObjectFactory],no JNDI name configured
Loaded Address[1]
Hibernate: select address0_.ADDRESS_ID as ADDRESS_ID0_, address0_.STREEt as STREEt0_, address0_.CITY as CITY0_ from ADDRESS address0_ where address0_.ADDRESS_ID=?
Process terminated with exit code 0


If a class is marked as lazy, when I load an instance of it using Session.load() it does not go to the DB. The SQL is fired only at the first access of a non-identifier property of the entity. Is this the expected behaviour? The JavaDoc for Session.load() says :
Code:
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.

You should not use this method to determine if an instance exists (use find() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.


If the ID passed to load() does not exist in the DB, shouldnt an error be raised immideately?

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 06, 2004 8:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, please refer to the documentation, and use get()


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