Java Reference
In-Depth Information
Listing 8.8. The JpaProductDAO class, which uses JPA classes to implement the DAO
The JPA implementation is wonderfully spare, but that's because it assumes the transaction
management is handled elsewhere and that Spring will handle allocating and closing the
necessary database resources.
I would never be comfortable writing that much code without a decent test case. Spring's
test context framework manages the application context, allows the test fixture to be injec-
ted, and, if a transaction manager is supplied, automatically rolls back transactions at the
end of each test.
To handle the transactions I used another Spring bean, JpaTransactionManager ,
which uses the entity manager factory previously specified:
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager"
p:entityManagerFactory-ref="entityManagerFactory" />
The resulting test case is shown in the following listing.
Search WWH ::




Custom Search