Tuesday, 5 July 2011

Use JPA-persist objects & JPA annotations & Hibernate as Engine (II)

1.Annotate each DAO method or the entire DAO class with @Transactional to make all
methods transactional.
(ensures operations within a DAO method in same transaction by same entity manager)

2.Enable declarative transaction management - [tx:annotationdriven]

3.[context:annotation-config /] - to allow inject entity managers into properties annotated with @PersistenceContext & allow inject entity manager factory into a property with the @PersistenceUnit annotation.

4.Enable [context:component-scan] - to allow @Repository annotation.

5.Register [bean class="org.springframework.dao.annotation.PersistenceException
TranslationPostProcessor" /] - to translate the native JPA exceptions into DataAccessException

6.Remember : transaction manager is needed no matter which transaction
management strategy (programmatic or declarative).
[bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"]
[property name="sessionFactory" ref="sessionFactory"/]

No comments:

Post a Comment