So I'm having a Spring and Hibernate configuration problem. I keep coming back to this error. Basically as I understand things, I want spring to open a hibernate session and hold this session open for the entire http request and the transaction managed by annotations. This is standard pattern no?
I'm using struts action classes that make calls out to service beans that in turn talk to hibernate.
Well the behaviour I'm seeing is my action makes requests to services annotated with '@Transactional'. In this particular case, my action class method (marked with @Transactional) makes a few calls out to some service classes this part works fine. But later in the method I reference a property of the database bean and I get a lazy load / no session exception.
Should not the session be held open for the length of the request. Here are my config settings thus far:
Code:
<bean id="hibernateDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="..."/>
<property name="url" value="..."/>
<property name="username" value="..."/>
<property name="password" value="..."/>
</bean>
<bean id="hibernateTxManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="hibernateDataSource"/>
</bean>
<tx:annotation-driven transaction-manager="hibernateTxManager" proxy-target-class="true"/>
<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="hibernateDataSource"/>
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" /-->
<property name="mappingLocations">
<list>
....
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="c3p0.max_size">50</prop>
<prop key="c3p0.min_size">10</prop>
</props>
</property>
</bean>
Is there anything obvious I am missing?
Thanks