tailieunhanh - manning Hibernate in Action phần 3

Tham khảo tài liệu 'manning hibernate in action phần 3', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Basic configuration 49 An application server exposes a connection pool as a JNDI-bound datasource an instance of . You need to tell Hibernate where to find the datasource in JNDI by supplying a fully qualified JNDI name. An example Hibernate configuration file for this scenario is shown in listing . Listing Sample for a container-provided datasource java comp env jdbc AuctionDB This file first gives the JNDI name of the datasource. The datasource must be configured in the J2EE enterprise application deployment descriptor this is a vendor-specific setting. Next you enable Hibernate integration with JTA. Now Hibernate needs to locate the application server s TransactionManager in order to integrate fully with the container transactions. No standard approach is defined by the J2EE specification but Hibernate includes support for all popular application servers. Finally of course the Hibernate SQL dialect is required. Now that you ve configured everything correctly using Hibernate in a managed environment isn t much different than using it in a non-managed environment Just create a Configuration with mappings and build a SessionFactory. However some of the transaction environment-related settings deserve some extra consideration. Java already has a standard transaction API JTA which is used to control transactions in a managed environment with J2EE. This is called container-managed transactions CMT . If a JTA transaction manager is present JDBC connections are enlisted with this manager and under its full control. This isn t the case in a nonmanaged environment where an application or the pool manages the JDBC connections and JDBC transactions