nathanmoon wrote:
Have you looked at this:
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#querysql-load? It says it works for stored procedures. I've never done it personally, though.
Thanks a lot for your answer. It has helped us a lot. Have you tried to use loader with stored procedures for associations ? We are trying to do this:
Hibernate Mapping:
<class name="Application" lazy="false" table="APPLICATIONS" schema="SEG" optimistic-lock="none">
<id name="applicationId" type="integer" unsaved-value="-1">
<column name="ID" not-null="true" unique="true" index="APP_PK"/>
<generator class="increment"/>
</id>
<property name="name" type="string">
<column name="NAME" length="16" not-null="true" unique="true" index="SQL051004114018480"/>
</property>
<property name="description" type="string">
<column name="DESC" length="50"/>
</property>
<set name="resources"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
order-by="ALIAS" >
<key foreign-key="RES_FK_APP">
<column name="APPID" not-null="true"/>
</key>
<one-to-many class="Resource"/>
<loader query-ref="loadResxApps"/>
</set>
<bag name="appRoles" lazy="false" inverse="true" cascade="all-delete-orphan">
<key foreign-key="APPROL_FK_APP">
<column name="APPID" not-null="true"/>
</key>
<one-to-many entity-name="co.com.grporg.bancolombia.security.beans.AppRole"/>
</bag>
<loader query-ref="loadApps"/>
<!--
<query-list query-ref="" name=""/>
-->
</class>
<!-- Loading SP -->
<sql-query name="loadApps" callable="true">
<return class="Application" />
{ call SEG.SEL_APPS(?) }
</sql-query>
<!-- Loading SP
Select {RES.*} from SEG.RESOURCES as RES where APPID = :id
{ call SEG.SEL_RESXAPPS(:id) }
-->
<sql-query name="loadResxApps" callable="true">
<load-collection alias="" role="Application.resources"/>
{ call SEG.SEL_RESXAPPS(?) }
</sql-query>
Currently, we can load the object but when we try to load the associated collection 'resources', we get this error:
Exception:
[10/14/05 14:36:31:843 COT] 2c96eb29 SystemOut O Hibernate: { call SEG.SEL_APPS(?) }
... OTHER STUFF...
[10/14/05 14:36:32:062 COT] 2c96eb29 SystemOut O Hibernate: { call SEG.SEL_RESXAPPS(?) }
[10/14/05 14:36:32:062 COT] 2c96eb29 JDBCException W org.hibernate.util.JDBCExceptionReporter SQL Error: -99999, SQLState: null
[10/14/05 14:36:32:077 COT] 2c96eb29 JDBCException E org.hibernate.util.JDBCExceptionReporter Invalid argument: unknown column name ID0_
[10/14/05 14:36:32:077 COT] 2c96eb29 DefaultLoadEv I org.hibernate.event.def.DefaultLoadEventListener Error performing load command
[10/14/05 14:36:32:077 COT] 2c96eb29 DefaultLoadEv I org.hibernate.event.def.DefaultLoadEventListener TRAS0014I: The following exception was logged org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:1591)
at org.hibernate.loader.Loader.list(Loader.java:1571)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1410)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at org.hibernate.persister.collection.NamedQueryCollectionInitializer.initialize(NamedQueryCollectionInitializer.java:49)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1426)
at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:274)
at org.hibernate.engine.PersistenceContext.initializeNonLazyCollections(PersistenceContext.java:796)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:216)
at org.hibernate.loader.Loader.doList(Loader.java:1588)
at org.hibernate.loader.Loader.list(Loader.java:1571)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:112)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1410)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:153)
at org.hibernate.persister.entity.NamedQueryLoader.load(NamedQueryLoader.java:55)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2471)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:351)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:332)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:113)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:151)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:79)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:603)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:596)
at co.com.grporg.bancolombia.security.dao.AbstractEntitieDAO.load(AbstractEntitieDAO.java:226)
at test.TestServlet.doOp(TestServlet.java:48)
at test.TestServlet.doGet(TestServlet.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)
Caused by: com.ibm.db2.jcc.b.SqlException: Invalid argument: unknown column name ID0_
Thanks a lot by any advise.