APPENDIX C n HIBERNATE AND SPRING 307 n (Hosting your own web site)

APPENDIX C n HIBERNATE AND SPRING 307 n HIBERNATE AND SPRING 307 To support transactional behavior, a transaction manager bean must first be applied to the session factory. Typically, this would be a HibernateTransactionManager in a self-contained application, or a JtaTransactionManager in an environment in which the container is managing transactions. Our application uses the Hibernate transaction manager, as declared in Listing C-14. Listing C-14. Declaring the HibernateTransactionManager Bean
The transaction manager must be notified of the session factory in use so that it can manage the transactions of the database connection configured in the session factory. If you want to be able to use nested transactions so that multiple calls to transactional methods can be made from a method that is itself enclosed in a transaction, you must set the nestedTransactionAllowed property on the HibernateTransactionManager bean. Note that Hibernate does not support the use of savepoints within nested transactions because it is unable to rollback the session cache s state. The transaction boundaries are applied to a bean by wrapping it in a proxy class that then honors the original bean s API as declared in its interface(s). Typically, the basis of the proxy is therefore declared as an abstract bean so that it can be applied to multiple DAO beans as required. For illustrative purposes, our example application also uses this approach (see Listing C-15). Listing C-15. Declaring the Default Transactionality for Our DAO Beans
PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED
With the transaction manager s template prepared, the declaration of any DAO objects must be wrapped in a bean declaration derived from this template. Our wrapped bean is shown in Listing C-16. The lines highlighted in bold are the wrapped bean s declaration since it is only used as a property for the enclosing proxy, it does not need to be assigned an id instead, the id of the paperDao proxy is used when a DAO reference is required. The proxy will honor the PaperDaointerface declared in Listing C-7.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply