Search code examples
hibernatejakarta-eeconnection-pooling

Replace Hibernate connection pool by container managed connection pool?


Can the hibernate connection-pool (like c3po) be replaced by the container managed datasource connection pool, or do those serve different purposes?

I defined my database datasource and connection-pool for that datasource in glassfish and referenced the datasource in the hibernate config file.

Is a connection-pool for hibernate itself still needed?


Solution

  • Normally Hibernate is configured to use a data source provided by an application server.

    This is especially useful, if you are using XA transactions, and you want the container to enlist all transactional resources (XA database connection, XA JMS sesions, ...) automatically in the global transaction.

    Further, if you use a data source of the application server, it removes a dependency on another library.

    If you do not have an application server (or a data source provider), then of course you need another one (like c3po) to fill that gap: This possibly applies to stand-alone applications or tests.