I want to test out hikaricp in TomEE. I have added the jar-file into my lib folder, and have tried defining the resources like this:
<Resource id="myJtaDs" type="DataSource" class-name="com.zaxxer.hikari.HikariJNDIFactory" factory-name="getObjectInstance">
....
</Resource>
When I do this I get the following error upon startup:
org.apache.xbean.recipe.MissingFactoryMethodException: Instance factory method has signature public com.zaxxer.hikari.HikariJNDIFactory.getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable) but expected signature public com.zaxxer.hikari.HikariJNDIFactory.getObjectInstance()
How can I define the HikariCP datasource in my tomee.xml?
You can wrap the HikariDataSource
within a JTADataSourceWrapperFactory
in order to get JTA support (see mail archives).
Then, you can define it via tomee.xml
or resource.xml
as follows:
<Resource id="hikariCP" class-name="com.zaxxer.hikari.HikariDataSource">
driverClassName org.hsqldb.jdbcDriver
jdbcUrl jdbc:hsqldb:mem:demo
username sa
password
<!-- other properties as required -->
</Resource>
<Resource id="demo" type="DataSource" class-name="org.apache.openejb.resource.jdbc.managed.JTADataSourceWrapperFactory" factory-name="create">
Delegate = hikariCP
</Resource>
In your persistence.xml
add the data source via
<jta-data-source>java:openejb/Resource/demo</jta-data-source>
Just ensure, that the HikariCP library is available within your classpath.
Side note: Setting hibernate.connection.provider_class
will create a connection pool within Hibernate, which is not managed by the container.