Java Reference
In-Depth Information
Listing 9-33. Launch-context.xml Configured for Hibernate Support
<bean id="sessionFactory"
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<property name="configurationClass">
<property name="hibernateProperties">
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<bean id="transactionManager"
<property name="sessionFactory" ref="sessionFactory" />
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"
<mapping class="com.apress.springbatch.chapter9.Customer"/>
Search WWH ::

Custom Search