Java Reference
In-Depth Information
Listing 9-33. Launch-context.xml Configured for Hibernate Support
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
lazy-init="true">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Again, this configuration should be familiar because it matches what you used in Chapter 7. You
begin the configuration with the SessionFactory . It relies on a dataSource (you recycle the same one
you've been using up to now); the location of the configuration, which in the case is a hibernate.cfg.xml
file in the root of the classpath; and a configurationClass to identify that you're using Hibernate's
annotation support to handle the mapping. Finally, you want to see the SQL that is being executed, so
you add the properties to tell Hibernate to log and format all SQL it generates.
The second part of the configuration in Listing 9-33 is the configuration of Hibernate's transaction
manager. It's important to note that you want to remove the one you've used up to now (and that's
included in launch-context.xml ) when you use Hibernate's transaction manager. This allows Spring
Batch and the Hibernate code to use the same transaction manager.
The second part of the SessionFactory configuration is the addition of a hibernate.cfg.xml file into
the <PROJECT_HOME>/src/main/resources directory. Listing 9-34 shows the contents of this file.
Listing 9-34. hibernate.cfg.xml
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
" http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="com.apress.springbatch.chapter9.Customer"/>
</session-factory>
</hibernate-configuration>
 
Search WWH ::




Custom Search