-->
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: Stored procedure queries
PostPosted: Wed Oct 24, 2007 5:06 am 
Newbie

Joined: Wed May 25, 2005 12:01 pm
Posts: 6
Hi!

I am trying to load collection UserCredential.persons via stored procedure call. I have set hbm.xml, sql query and stored procedure which are attached below.

Loading of persons Set is done by
Code:
Set set = userCredential.getPersons();


But after this I am getting the exception "failed to lazily initialize a collection of role" (see below) when trying to access values in retrieved Set.

Is there something wrong with HBMs or I am using it wrong?

I am using Spring 2.0.6 and openSessionInViewInterceptor.


Hibernate version: 3.2.5

Mapping documents:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.company.generated.UserCredential" table="USER_CREDENTIAL">
        <id name="id" type="java.lang.Long">
            <column name="ID" precision="10" scale="0" />
            <generator class="sequence">
                <param name="sequence">SEQ_USER_CREDENTIAL</param>
            </generator>
        </id>
        <many-to-one name="role" class="com.company.generated.Role" fetch="select">
            <column name="ID_ROLE" precision="10" scale="0" />
        </many-to-one>
        <many-to-one name="userStatus" class="com.company.generated.UserStatus" fetch="select">
            <column name="ID_USER_STATUS" precision="10" scale="0" />
        </many-to-one>
        <property name="username" type="string">
            <column name="USERNAME" length="100" unique="true" />
        </property>
        <property name="password" type="string">
            <column name="PASSWORD" length="20" />
        </property>
        <property name="expirationDate" type="timestamp">
            <column name="EXPIRATION_DATE" length="7" />
        </property>
        <property name="idUserChange" type="java.lang.Long">
            <column name="ID_USER_CHANGE" precision="10" scale="0" />
        </property>
        <set name="persons" inverse="true">
            <key/>
            <one-to-many class="com.company.generated.Person" />
           
            <loader query-ref="persons"/>
        </set>
    </class>
</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.company.generated.Person">
        <id name="id" type="java.lang.Long">
            <generator class="increment"/>
        </id>
       
        <property name="firstName" type="string">
            <column name="FIRST_NAME" length="20" />
        </property>
        <property name="middleName" type="string">
            <column name="MIDDLE_NAME" length="20" />
        </property>
        <property name="lastName" type="string">
            <column name="LAST_NAME" length="20" />
        </property>
    </class>
</hibernate-mapping>



Code:
<sql-query name="persons" callable="true">
   <load-collection alias="emp" role="com.company.generated.UserCredential.persons"/>
   { ? = call PKG_PRESS.GET_PERSON(:id_user) }
</sql-query>


Code:
FUNCTION GET_PERSON (P_ID_USER_CREDENT NUMBER) RETURN SYS_REFCURSOR IS
  ref_cur_person SYS_REFCURSOR; 
BEGIN
   OPEN ref_cur_person FOR   
    SELECT *
    FROM PERSON
    WHERE ID_USER_CREDENT = P_ID_USER_CREDENT;
   RETURN ref_cur_person;
END;


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Code:
2007-10-24 10:39:30,406 ERROR [org.hibernate.LazyInitializationException] - failed to lazily initialize a collection of role: com.company.generated.UserCredential.persons, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.company.generated.UserCredential.persons, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
   at org.hibernate.collection.PersistentSet.toString(PersistentSet.java:309)
   at com.company.login.SaodUserPrincipal.<init>(SaodUserPrincipal.java:30)
   at com.company.login.SaodUserDetailsService.loadUserByUsername(SaodUserDetailsService.java:40)
   at org.acegisecurity.providers.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:100)
   at org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:119)
   at com.company.login.SaodDaoAuthenticationProvider.authenticate(SaodDaoAuthenticationProvider.java:37)
   at org.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:195)
   at org.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:45)
   at org.acegisecurity.ui.webapp.AuthenticationProcessingFilter.attemptAuthentication(AuthenticationProcessingFilter.java:71)
   at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:211)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
   at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:286)
   at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
   at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
   at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
   at java.lang.Thread.run(Thread.java:595)


Name and version of the database you are using:
Oracle 10g


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.