Guys,
Was hoping one of you kind fellas can help with this one.
Basically, I have written an SP for custom loading.
- Its is used as a namedQuery to populate the objects.
- I also wanted to use it to re-load my objects when calling session.refresh. (SP's use some logic to populate some of the properties - and need these values back)
I have added the <loader query-ref="LoadSubGroup" /> in the mapping document, howver after inserting and calling session.refresh
Session session = HibernateUtils.openSession();
Transaction tx = session.beginTransaction();
session.save(subGrp);
tx.commit();
session.refresh(subGrp);
HibernateUtils.closeSession();
I get the an error saying
[2005-08-08 11:19:02,635] [org.hibernate.AssertionFailure] ERROR [main] (AssertionFailure.java:22) - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: cannot supply object to query loader
Not sure if I am doing something wrong. Please advise.
Thanks in advance for your help.
Naz
PS : Full mapping details, code and exception below
Hibernate version: 3.0.5
Mapping documents:
<hibernate-mapping>
<class name="com.tds.refdata.admin.SubGroup" table="T_SUB_GROUP">
<id name="subGroupId" type="integer" column="id_sub_grp_key" unsaved-value="null"/>
<version name="subGroupVersion" type="integer" column="id_sub_grp_ver" unsaved-value="negative"/>
<property name="active" type="boolean" column="is_actv" />
<property name="dsRegion" type="integer" column="id_ds_rgn" />
<property name="lastModifiedBy" type="string" column="id_lst_upd" />
<property name="strLastModifiedDate" type="string" column="dt_lst_upd_gmt" />
<property name="subGroupName" type="string" column="nm_sub_grp" />
<property name="subGroupDescription" type="string" column="nm_sub_grp_desc" />
<property name="regionKey" type="integer" column="id_rgn_key" />
<property name="groupId" type="integer" column="id_grp_key" />
<property name="groupName" type="string" column="nm_grp" insert="false" update="false" />
<property name="regionName" type="string" column="nm_rgn" insert="false" update="false"/>
<loader query-ref="LoadSubGroup" />
<sql-insert callable="true">{call INS_UPD_sub_group_hbm (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}</sql-insert>
<sql-update callable="true">{? = call INS_UPD_sub_group_hbm (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}</sql-update>
<!--sql-delete callable="true">{? = call deletePerson (?)}</sql-delete-->
</class>
<!-- hibernate-mapping Loading SP -->
<sql-query name="LoadSubGroup" callable="true">
<return alias="subgrp" class="com.tds.refdata.admin.SubGroup">
<return-property name="subGroupId" column="id_sub_grp_key" />
<return-property name="subGroupVersion" column="id_sub_grp_ver" />
<return-property name="active" column="is_actv" />
<return-property name="dsRegion" column="id_ds_rgn" />
<return-property name="lastModifiedBy" column="id_lst_upd" />
<return-property name="strLastModifiedDate" column="dt_lst_upd_gmt" />
<return-property name="subGroupName" column="nm_sub_grp" />
<return-property name="subGroupDescription" column="nm_sub_grp_desc" />
<return-property name="regionKey" column="id_rgn_key" />
<return-property name="groupId" column="id_grp_key" />
<return-property name="groupName" column="nm_grp" />
<return-property name="regionName" column="nm_rgn" />
</return>
{ call SEL_sub_group(?)}
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtils.openSession();
Transaction tx = session.beginTransaction();
session.save(subGrp);
tx.commit();
//HibernateUtils.closeSession();
//session = HibernateUtils.openSession();
//session.load(subGrp, subGrp.getSubGroupId());
session.refresh(subGrp);
HibernateUtils.closeSession();
Full stack trace of any exception that occurs:
[2005-08-08 11:19:02,635] [org.hibernate.AssertionFailure] ERROR [main] (AssertionFailure.java:22) - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: cannot supply object to query loader
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:104)
at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:679)
at com.tds.refdata.admin.SubGroupAdmin.save(SubGroupAdmin.java:87)
at com.tds.refdata.admin.SubGroupAdmin.addSubGroup(SubGroupAdmin.java:125)
at com.tds.refdata.admin.SubGroupAdminTest.testAddSubGroup(SubGroupAdminTest.java:70)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:567)
[2005-08-08 11:19:02,635] [com.tds.refdata.admin.SubGroupAdmin] ERROR [main] (SubGroupAdmin.java:96) - org.hibernate.AssertionFailure: cannot supply object to query loader
org.hibernate.AssertionFailure: cannot supply object to query loader
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:37)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:104)
at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:679)
at com.tds.refdata.admin.SubGroupAdmin.save(SubGroupAdmin.java:87)
at com.tds.refdata.admin.SubGroupAdmin.addSubGroup(SubGroupAdmin.java:125)
at com.tds.refdata.admin.SubGroupAdminTest.testAddSubGroup(SubGroupAdminTest.java:70)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
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.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:297)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:672)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:567)
Name and version of the database you are using:
MS SQL SERVER 2002
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
|