Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Mon May 23 16:22:08 CDT 2005 -->
<hibernate-mapping package="model">
<class name="Parent" table="parent">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="firstName" column="first_name" type="java.lang.String" not-null="true"
lazy="true"/>
<property name="lastName" column="last_name" type="java.lang.String" not-null="true"
lazy="true"/>
<property name="age" column="age" type="java.lang.Integer" not-null="true"
lazy="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
public Parent retrieveParent(int id) {
Session s = HibernateSessionFactory.currentSession();
Query q = s.createQuery("from Parent where id = " + id);
return (Parent) q.uniqueResult();
}
public static void main(String[] args) throws Exception{
Driver d = new Driver();
Parent p = d.retrieveParent(1);
Integer age = p.getAge();
HibernateSessionFactory.closeSession();
}
Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
MySql latest release
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
16:26:17,281 INFO Environment:464 - Hibernate 3.0.2
16:26:17,296 INFO Environment:477 - hibernate.properties not found
16:26:17,312 INFO Environment:510 - using CGLIB reflection optimizer
16:26:17,312 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
16:26:17,515 INFO Configuration:1160 - configuring from resource: /com/hibernate.cfg.xml
16:26:17,515 INFO Configuration:1131 - Configuration resource: /com/hibernate.cfg.xml
16:26:18,046 INFO Configuration:441 - Mapping resource: model/Child.hbm.xml
16:26:18,250 INFO HbmBinder:258 - Mapping class: model.Child -> child
16:26:18,453 INFO Configuration:441 - Mapping resource: model/Parent.hbm.xml
16:26:18,593 INFO HbmBinder:258 - Mapping class: model.Parent -> parent
16:26:18,625 INFO Configuration:1272 - Configured SessionFactory: null
16:26:18,625 INFO Configuration:852 - processing extends queue
16:26:18,625 INFO Configuration:856 - processing collection mappings
16:26:18,625 INFO Configuration:865 - processing association property references
16:26:18,625 INFO Configuration:894 - processing foreign key constraints
16:26:18,625 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
16:26:18,625 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
16:26:18,625 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
16:26:18,640 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/acme
16:26:18,640 INFO DriverManagerConnectionProvider:86 - connection properties: {user=root, password=****}
16:26:19,250 INFO SettingsFactory:71 - RDBMS: MySQL, version: 4.1.10a-nt
16:26:19,250 INFO SettingsFactory:72 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.8 ( $Date: 2005/04/14 20:36:13 $, $Revision: 1.27.4.64 $ )
16:26:19,296 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLDialect
16:26:19,312 INFO SettingsFactory:122 - JDBC batch size: 15
16:26:19,312 INFO SettingsFactory:125 - JDBC batch updates for versioned data: disabled
16:26:19,312 INFO SettingsFactory:130 - Scrollable result sets: enabled
16:26:19,312 INFO SettingsFactory:138 - JDBC3 getGeneratedKeys(): enabled
16:26:19,312 INFO SettingsFactory:150 - Aggressive release : disabled
16:26:19,312 INFO SettingsFactory:163 - Maximum outer join fetch depth: 2
16:26:19,312 INFO SettingsFactory:166 - Default batch fetch size: 1
16:26:19,312 INFO SettingsFactory:170 - Generate SQL with comments: disabled
16:26:19,328 INFO SettingsFactory:174 - Order SQL updates by primary key: disabled
16:26:19,328 INFO SettingsFactory:312 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
16:26:19,328 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
16:26:19,328 INFO SettingsFactory:182 - Query language substitutions: {}
16:26:19,328 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
16:26:19,328 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
16:26:19,328 INFO SettingsFactory:191 - Automatic flush during beforeCompletion(): disabled
16:26:19,328 INFO SettingsFactory:195 - Automatic session close at end of transaction: disabled
16:26:19,328 INFO SettingsFactory:201 - Second-level cache: enabled
16:26:19,328 INFO SettingsFactory:205 - Query cache: disabled
16:26:19,328 INFO SettingsFactory:299 - Cache provider: org.hibernate.cache.EhCacheProvider
16:26:19,343 INFO SettingsFactory:220 - Optimize cache for minimal puts: disabled
16:26:19,343 INFO SettingsFactory:229 - Structured second-level cache entries: enabled
16:26:19,343 INFO SettingsFactory:249 - Echoing all SQL to stdout
16:26:19,343 INFO SettingsFactory:253 - Statistics: disabled
16:26:19,343 INFO SettingsFactory:257 - Deleted entity synthetic identifier rollback: disabled
16:26:19,343 INFO SettingsFactory:271 - Default entity-mode: pojo
16:26:19,625 INFO SessionFactoryImpl:148 - building session factory
16:26:19,656 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/eclipse/workspace/Dynamic%20Object%20Retrieval/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
16:26:19,921 INFO EntityMetamodel:190 - lazy property fetching available for: model.Parent
16:26:20,296 INFO EntityMetamodel:190 - lazy property fetching available for: model.Child
16:26:20,640 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
16:26:20,640 INFO SessionFactoryImpl:374 - Checking 0 named queries
Hibernate: select parent0_.id as id from parent parent0_ where parent0_.id=1
Question: after stepping through the code above how come p.getAge() returns null? As you can see from the debug I ran insturmentation.