class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan"
value="com.apress.prospring3.ch10.domain"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.H2Dialect
</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<context:annotation-config/>
<context:component-scan
base-package="com.apress.prospring3.ch10.service.jpa" />
</beans>
In the previous configuration, several beans are declared in order to be able to support the
configuration of LocalContainerEntityManagerFactoryBean with Hibernate as the persistence provider.
The main configurations are as follows:
The dataSource bean: We declared the datasource with an embedded database
·
using H2. Because it's an embedded database, the database name is not required.
The transactionManager bean: The entity manager factory requires a transaction
·
manager for transactional data access. Spring provides a transaction manager
specifically for JPA (org.springframework.orm.jpa.JpaTransactionManager). The
bean is declared with an ID of transactionManager assigned. We will discuss
transactions in detail in Chapter 13. We declare the tag <tx:annotation-driven>
to support a declaration of the transaction demarcation requirements using
annotations.
Component scan: The tag should be familiar to you. We instruct Spring to scan the
·
components under the package com.apress.prospring3.ch10.service.jpa.
JPA EntityManagerFactory bean (emf): The emf bean is the most important part.
·
First, we declare the bean to use the LocalContainerEntityManagerFactoryBean.
Within the bean, several properties are provided. First, as you might expected,
we need to inject the datasource bean. Second, we configure the property
jpaVendorAdapter with the class HibernateJpaVendorAdapter, because we are using
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home