-->
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: Using HQL for Class loader query
PostPosted: Wed Sep 05, 2007 3:36 am 
Newbie

Joined: Thu Oct 06, 2005 5:26 am
Posts: 17
I'm having a problem using HQL in a loader query for a class. If I use a SQL query instead it works fine and the class is loaded. I can see the SQL generated from the HQL is correct and using Profiler on the database I can see that the single parameter to the SQL is correct. However, the row that is found is not populated in the class.

Is it possible to use HQL as a class loader?

Hibernate version:
3.2.5

Mapping documents:
<hibernate-mapping package="com.tibco.n2.brm.model">
<class name="WorkItemModel" table="work_items" lazy="true">
<id name="id" type="long">
<column name="work_item_id" />
<generator class="identity" />
</id>
<property name="version" column="version" type="long" not-null="true"/>
<property name="resultSetSize" column="ResultSet" insert="false" update="false" type="long" not-null="false"/>
<component name="header" class="WorkItemHeaderModel" insert="true" update="true" lazy="true">
<property name="description" column="description" type="string" not-null="false"/>
<property name="priority" column="priority" type="int" not-null="true"/>
<property name="resourceExpr" column="resource_expr" type="int" not-null="false"/>
<property name="startDate" column="start_date" type="timestamp" not-null="false"/>
<property name="targetDate" column="target_date" type="timestamp" not-null="false"/>
<property name="allocated" column="allocated" type="boolean" not-null="true"/>
<property name="opened" column="opened" type="boolean" not-null="true"/>
</component>
<loader query-ref="getWorkItemHQL"/>
</class>
<query name="getWorkItemHQL">
<![CDATA[
SELECT wi.id,wi.version,wi.header FROM WorkItemModel wi WHERE wi.id=?
]]>
</query>
<sql-query name="getWorkItemSQL">
<return alias="wi" class="WorkItemModel" lock-mode="read" />
<![CDATA[
SELECT wi.work_item_id,wi.version,wi.description,wi.priority,wi.resource_expr,wi.start_date,
wi.target_date,wi.allocated,wi.opened, 1 'ResultSet' FROM work_items wi WHERE wi.work_item_id=?
]]>
</sql-query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
protected Object findById(Class clazz, Long id)
{
return getHibernateTemplate().load(clazz, id);
}

Full stack trace of any exception that occurs:
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.tibco.n2.brm.model.WorkItemModel#1]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:140)
at com.tibco.n2.brm.model.WorkItemModel$$EnhancerByCGLIB$$99d45d52.getVersion(<generated>)
at com.tibco.n2.brm.orm.test.WorkItemDAOImplTest.testFindByObjectID(WorkItemDAOImplTest.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database you are using:
SQL 2005

The generated SQL (show_sql=true):
select workitemmo0_.work_item_id as col_0_0_, workitemmo0_.version as col_1_0_, workitemmo0_.description as col_2_0_, workitemmo0_.priority as col_2_1_, workitemmo0_.resource_expr as col_2_2_, workitemmo0_.start_date as col_2_3_, workitemmo0_.target_date as col_2_4_, workitemmo0_.allocated as col_2_5_, workitemmo0_.opened as col_2_6_ from work_items workitemmo0_ where workitemmo0_.work_item_id=?

Debug level Hibernate log excerpt:
2007-09-05 08:27:48,312 DEBUG HibernateTemplate: - Found thread-bound Session for HibernateTemplate
2007-09-05 08:27:48,328 DEBUG HibernateTemplate: - Not closing pre-bound Hibernate Session after HibernateTemplate
2007-09-05 08:27:48,328 DEBUG TransactionInterceptor: - Completing transaction for [com.tibco.n2.brm.orm.WorkItemDAO.findByObjectID]
Hibernate: select workitemmo0_.work_item_id as col_0_0_, workitemmo0_.version as col_1_0_, workitemmo0_.description as col_2_0_, workitemmo0_.priority as col_2_1_, workitemmo0_.resource_expr as col_2_2_, workitemmo0_.start_date as col_2_3_, workitemmo0_.target_date as col_2_4_, workitemmo0_.allocated as col_2_5_, workitemmo0_.opened as col_2_6_ from work_items workitemmo0_ where workitemmo0_.work_item_id=?
2007-09-05 08:27:48,359 DEBUG TransactionSynchronizationManager: - Retrieved value [org.springframework.jdbc.datasource.ConnectionHolder@1f94884] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@42f352] bound to thread [main]
2007-09-05 08:27:48,406 DEBUG HibernateTransactionManager: - Triggering beforeCompletion synchronization
2007-09-05 08:27:48,406 DEBUG HibernateTransactionManager: - Initiating transaction rollback
2007-09-05 08:27:48,406 DEBUG HibernateTransactionManager: - Rolling back Hibernate transaction on Session [org.hibernate.impl.SessionImpl@7f8922]
2007-09-05 08:27:48,406 DEBUG HibernateTransactionManager: - Triggering afterCompletion synchronization
2007-09-05 08:27:48,406 DEBUG TransactionSynchronizationManager: - Clearing transaction synchronization
2007-09-05 08:27:48,406 DEBUG TransactionSynchronizationManager: - Removed value [org.springframework.orm.hibernate3.SessionHolder@63b2e6] for key [org.hibernate.impl.SessionFactoryImpl@1762fc7] from thread [main]
2007-09-05 08:27:48,406 DEBUG TransactionSynchronizationManager: - Removed value [org.springframework.jdbc.datasource.ConnectionHolder@1f94884] for key [org.springframework.jdbc.datasource.DriverManagerDataSource@42f352] from thread [main]
2007-09-05 08:27:48,406 DEBUG HibernateTransactionManager: - Closing Hibernate Session [org.hibernate.impl.SessionImpl@7f8922] after transaction
2007-09-05 08:27:48,406 DEBUG SessionFactoryUtils: - Closing Hibernate Session
2007-09-05 08:27:48,406 DEBUG DataSourceUtils: - Returning JDBC Connection to DataSource


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.