Java Reference
In-Depth Information
Listing C-17 Declaring the OpenSessionInViewInterceptor for Use in the Spring View
<bean name="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
<property name="singleSession" value="true"/>
</bean>
The interceptor needs to control the behavior of the session factory, so we must provide it
with a reference to the appropriate bean. We can also dictate whether a single Session object
will be used for the entire duration of the user request. Setting this to true is the most efficient
approach, and therefore the default; however, it has potential side effects, particularly if
declarative transactions are not in use. When set to false , individual sessions will be acquired
for each DAO operation.
The Sample Configuration File
Listing C-18 shows the full Spring configuration file of our example application as a handy ref-
erence to what's required in creating a Hibernate-based Spring application.
Listing C-18. The Complete Spring Configuration File
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Hibernate configurations -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configurationClass"
value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="configLocation"
value="classpath:hibernate.cfg.xml" />
</bean>
<bean name="openSessionInViewInterceptor"
class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
Search WWH ::




Custom Search