In stand alone application which is build on top of hibernate I like to use Tomcat JDBC Connection Pool.
My guess is that i need to add some configs in hibernate.cfg.xml.
Can someone guide me how to configure hibernate to use "Tomcat JDBC Connection Pool" as connection pool.
In your hibernate.cfg.xml configuration file, you need to set the following property:
hibernate.connection.datasource=java:/comp/env/jdbc/TestDB
assuming this is the JNDI name of your Tomcat CP DataSource.
Related
I have the following tomcat connection pool configuration from spring-boot-1.x. As of spring 2 the default is hikaricp. How can I migrate the following properties to the hikari pendant? I could not find them:
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.initial-size=1
spring.datasource.tomcat.max-idle
spring.datasource.tomcat.initial-size
spring.datasource.tomcat.max-age
spring.datasource.tomcat.test-while-idle
spring.datasource.tomcat.test-on-connect
spring.datasource.tomcat.test-on-return
spring.datasource.tomcat.time-between-eviction-runs-mills
spring.datasource.hikari.*?
You can find all possible properties for HikariCP here.
Although some of the properties you define, are nonexistant in Hikari because of a completely different implementation. Some of them are not even needed anymore.
I need to use Atomikos transaction Manager with Tomcat 8.0.36 to support JTA. Every documentation for Atomikos, recommend using com.atomikos.jdbc.AtomikosDataSourceBean as the type and com.atomikos.tomcat.EnhancedTomcatAtomikosBeanFactory as the object factory for the datasource resource (specified as resource in tomcat's context.xml)
However, if we use com.atomikos.jdbc.AtomikosDataSourceBean, Atomikos will use its own JDBC connection Pool instead of Tomcat's connection Pool.
Tomcat's connection pool provides more configurable settings than atomikos.
Is it possible to use Datasource resource, with type as javax.sql.XADatasource and factory as org.apace.tomcat.jdbc.pool.DatasourceFactory (which will use Tomcat's XA connection Pool) with Atomikos?
I tried to use atomikos with tomcat JDBC pool i.e. I didn't use AtomikosDatasourceBean (which is the only recommended way in Atomikos documentation). So far I have tested this with 3-4 applications and it seems to work fine.
Atomikos documentation doesn't provide much detail about it, however, there is one sentence on its website which says that we can use other JDBC pool with tomcat.
is it possible to intercept the connection pooling mechanism of a DataSource in a JEE container?
For (un)setting some information on the connection's context I'm searching for a way to intercept the pooling mechanism so that I know when and which connection is put back into the pool.
So does anyone know a (common) way to do this?
Some additional info:
The application runs on Wildfly
Using Hibernate for ORM
The option connection-listener in datasource configuration can be the solution.
connection-listener:
An org.jboss.jca.adapters.jdbc.spi.listener.ConnectionListener that
provides a possible to listen for connection activation and
passivation in order to perform actions before the connection is
returned to the application or returned to the pool
You can create a custom implementation of org.jboss.jca.adapters.jdbc.spi.listener.ConnectionListener and deploy it as a module to do that you want.
I am a beginner working on a project in Netbeans and using Glasshfish, but I have to deploy on TOMCAT on Elastic BeanStalk. I don't know anything about tomcat. To connect to my database, I use Entity Classes and a named connection jdbc/whatever (I hear this is called a JDNI name) in my persistence.xml.
On the Glassfish server bundled with Netbeans, I added a Connection pool and a JDBC resource. This was done with a GUI. It was super simple. Create the JDBC connection pool after you stuffed the right driver in the right folder by pointing to the location of server/password/etc. Then point the jdbc resource at the pool.
Now I need to do this with TOMCAT and XML. I have no idea what I am doing...
How do I create a connection pool which all my applications can reach?
How do I then get JNDI? set up that persistence.xml can reference and make the magic db stuff happen?
How do I then set up a jdbc authentication realm based on this database?
It was magic in Glassfish is it was so GUI. But I don't have a GUI for TOMCAT.
I am using spring.
Part of my project is to enhance the thread-safety part of my application. I want to be able to store and retrieve data from a mysql database through JDBC Connector/J and I know that I need to use connection pooling for this but my application is not a servlet ... Should I still install Tomcat and change the config.xml file for the connection pooling datasource, connection numbers etc...?
You don't need a servlet or webapp to use db connection pooling. I'm sure there are a plenty of pools to use, my default is apache dbcp http://commons.apache.org/dbcp/
To use dbcp you need to have the commons-dbcp-1.4.jar (for version 1.4) and the commons-pool (http://commons.apache.org/pool/) in your classpath.
A simple way to use pooling, is to use the org.apache.commons.dbcp.BasicDataSource
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUsername(username);
ds.setPassword(password);
ds.setUrl(jdbcUrl);
ds.setInitialSize(4);
Then, you can get connections out of the pool by calling ds.getConnection() .
Furthermore, you need to configure the maximum count of active connections, have a look at the BasicDataSource API.
You can use c3p0 instead.
You can find the entire documentation here :
c3p0 - JDBC3 Connection