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?