How to configure HikariCP via Tomee.xml?
Asked Answered
M

2

5

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?

Mercurio answered 19/3, 2018 at 15:8 Comment(0)
O
4

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.

Organography answered 30/3, 2021 at 13:36 Comment(0)
N
2

I haven't done through tomee.xml, But tried with JPA using HsqlDB. below are JPA persistence.xml properties.Good Luck.

<properties>
    <property name="hibernate.connection.provider_class" value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider"/>
    <property name="hibernate.hikari.dataSourceClassName" value="org.hsqldb.jdbc.JDBCDataSource"/>
    <property name="hibernate.hikari.dataSource.url" value="jdbc:hsqldb:mem:test"/>
    <property name="hibernate.hikari.dataSource.user" value="sa"/>
    <property name="hibernate.hikari.dataSource.password" value=""/>
    <property name="hibernate.hikari.connectionTimeout" value="1200"/>
    <property name="hibernate.hikari.connectionTestQuery" value="select 1 from INFORMATION_SCHEMA.SYSTEM_USERS"/>

    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
    <property name="hibernate.hbm2ddl.auto" value="create-drop" />
    <property name="hibernate.enable_lazy_load_no_trans" value="true"/>


</properties>
Nelsen answered 11/12, 2018 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.