I think before giving a short answer... I will give you a detailed explanation via a links:

http://wiki.apache.org/myfaces/HibernateAndMyFaces?highlight=%28hibernate%29

This small article describes exactly the problems you run into and how to solve them...

Werner



Rick Gruber-Riemer wrote:
Hej

I use MyFaces (1.0.9), Hibernate (3.0.5) and Spring (1.22) in my 
webapplication. When I get a list of records from the database in a table or 
make a new record using a form everything works fine. However when I try to 
edit a record in a form, I get a org.hibernate.LazyInitializationException 
error on opening the editform.
I understand this has something to do with the Hibernate sessions. And it has 
nothing to do with MyFaces in particular. And I have found some hints by 
googeling like Spring's OpenSessionInViewFilter. However I do not have a clue 
what to change where in the configuration.

=> Has somebody used JSF+Spring+Hibernate successfully?
=> Downloadable sample code?
=> Do I need the jsf-spring integration library?

Any hint would be much appreciated ... Rick

<hibernate-mapping>
        <class 
name="dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink"
                table="DANAFILE.SCANJOUR_LINK">
                <id name="id" type="long" column="ROW_ID">
                        <meta attribute="scope-set">protected</meta>
                        <generator class="sequence">
                <param name="sequence">DANAFILE.SEQNUMBER</param>
                </generator>
        </id>
                <version column="REVISION" name="revision" />
                <property name="objId" type="string" not-null="true"/>
                <property name="scanJourNumber" type="int" column="SCANJOUR_NUMBER" 
not-null="true"/>
                <property name="notes" type="string" column="NOTES" 
not-null="false"/>
                <property name="active" type="yes_no" column="ACTIVE" 
not-null="true" />
                <property name="createdBy" type="string" column="CREATED_BY" 
not-null="true"/>
                <property name="lastUpdatedBy" type="string" column="LAST_UPD_BY" 
not-null="true"/>
                <property name="createdDate" type="timestamp" column="CREATED_DT" 
not-null="true"/>
                <property name="lastUpdatedDate" type="timestamp" column="LAST_UPD_DT" 
not-null="true"/>          
        </class>
</hibernate-mapping>

<beans>
        <bean id="danafileHbmDS" class="oracle.jdbc.pool.OracleDataSource">
                <property 
name="driverType"><value>oracle.jdbc.OracleDriver</value></property>
                <property 
name="URL"><value>jdbc:oracle:thin:@10.0.0.3:1521:dhdvl</value></property>
                <property name="user"><value>danafile_web</value></property>
                <property name="password"><value>styr3ls3n</value></property>
        </bean>
        
        <!-- Hibernate SessionFactories -->
        <bean id="danafileHbmSF" 
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
                <property name="dataSource"><ref 
local="danafileHbmDS"/></property>
                <property name="mappingResources">
                        <list>
                                
<value>dk/trafikstyrelsen/data/transfer/dto/railsecurity/danafile/ScanJourLink.hbm.xml</value>
                        </list>
                </property>
                <property name="hibernateProperties">
                        <props>
                                <prop 
key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop>
                                <prop key="hibernate.query.substitutions">yes 'Y', no 
'N'</prop>
                                <prop key="hibernate.show_sql">true</prop>
                        </props>
                </property>
        </bean>

        <!-- Transaction manager for a single Hibernate SessionFactory 
(alternative to JTA) -->
        <bean id="transactionManager" 
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
                <property name="sessionFactory"><ref 
local="danafileHbmSF"/></property>
        </bean>
                
        <bean id="scanJourLinkDAO" 
class="dk.trafikstyrelsen.data.transfer.dao.railsecurity.danafile.ScanJourLinkHbmDAO">
                <property name="sessionFactory"><ref 
local="danafileHbmSF"/></property>
        </bean>
</beans>


ERROR - LazyInitializationException.<init>(19) | could not initialize proxy - 
the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the 
owning Session was closed
        at 
org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
        at 
org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
        at 
org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
        at 
dk.trafikstyrelsen.data.transfer.dto.railsecurity.danafile.ScanJourLink$$EnhancerByCGLIB$$c24a4569.getScanJourNumber(<generated>)
        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 
org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:419)
        at 
org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:104)
        at 
org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java:555)
        at org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
        at 
org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:441)

Reply via email to