-->
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: Using SP for Custom Loading
PostPosted: Sun Aug 07, 2005 10:39 pm 
Newbie

Joined: Fri Mar 25, 2005 3:07 pm
Posts: 11
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:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 2:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
please report this in jira

_________________
Max
Don't forget to rate


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.