Skip to content

Commit

Permalink
[KIE-990] Replace hibernate with openjpa in persistence tests (#5764)
Browse files Browse the repository at this point in the history
* [KIE-990] Replace hibernate with openjpa in persistence tests

* replace build time openjpa enhancement with runtime one
  • Loading branch information
mariofusco authored Mar 6, 2024
1 parent 30e2da3 commit d26490d
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 126 deletions.
59 changes: 13 additions & 46 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
<version.org.glassfish.jaxb>4.0.4</version.org.glassfish.jaxb>
<!--This needs to be in sync with JUnit-->
<version.org.hamcrest>1.3</version.org.hamcrest>
<version.org.hibernate>6.2.18.Final</version.org.hibernate>
<version.org.hsqldb>2.3.0</version.org.hsqldb>
<version.org.infinispan>14.0.13.Final</version.org.infinispan>
<version.org.javassist>3.26.0-GA</version.org.javassist>
<version.org.jboss.narayana.tomcat>6.0.1.Final</version.org.jboss.narayana.tomcat>
<version.org.jboss.logging>3.5.3.Final</version.org.jboss.logging>
<version.org.jboss.transaction.spi>7.6.1.Final</version.org.jboss.transaction.spi>
<version.org.jboss.weld.weld>3.1.6.Final</version.org.jboss.weld.weld>
<version.org.eclipse.microprofile.config>3.0.3</version.org.eclipse.microprofile.config>
Expand All @@ -123,6 +123,7 @@
<version.jakarta.json.bind-api>3.0.0</version.jakarta.json.bind-api>
<version.jakarta.json>1.1.5</version.jakarta.json>
<version.jakarta.json-api>2.1.2</version.jakarta.json-api>
<version.org.apache.openjpa>4.0.0</version.org.apache.openjpa>
<version.org.jpmml.model>1.6.4</version.org.jpmml.model> <!-- jpmml-model BSD 3C license - ATTENTION 1.5.1 intentional, because 1.5.1 evaluators works with 1.5.1 -->
<version.org.junit>5.9.3</version.org.junit>
<version.org.mvel>2.5.1.Final</version.org.mvel>
Expand Down Expand Up @@ -375,11 +376,6 @@
<artifactId>xstream</artifactId>
<version>${version.com.thoughtworks.xstream}</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream-hibernate</artifactId>
<version>${version.com.thoughtworks.xstream}</version>
</dependency>

<dependency>
<groupId>guru.nidi</groupId>
Expand Down Expand Up @@ -777,23 +773,6 @@
<version>${version.org.hamcrest}</version>
</dependency>

<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-envers</artifactId>
<version>${version.org.hibernate}</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${version.org.hibernate}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
Expand Down Expand Up @@ -1099,29 +1078,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.org.hibernate}</version>
<exclusions>
<exclusion>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>javax.activation-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Required for Errai Dynamic Bean validation -->
<dependency>
<groupId>jakarta.validation</groupId>
Expand Down Expand Up @@ -1288,6 +1244,17 @@
<artifactId>microprofile-config-api</artifactId>
<version>${version.org.eclipse.microprofile.config}</version>
</dependency>

<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${version.org.apache.openjpa}</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${version.org.jboss.logging}</version>
</dependency>
</dependencies>

</dependencyManagement>
Expand Down
26 changes: 11 additions & 15 deletions drools-persistence/drools-persistence-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@

<!-- These are properties used in the database profiles. Some of them must be initialized
to be empty so that Maven applies their values via filtering to the resources. -->
<maven.hibernate.dialect>org.hibernate.dialect.H2Dialect</maven.hibernate.dialect>
<maven.datasource.classname>org.h2.jdbcx.JdbcDataSource</maven.datasource.classname>
<maven.jdbc.driver.class>org.h2.Driver</maven.jdbc.driver.class>
<maven.jdbc.db.name/>
Expand Down Expand Up @@ -74,6 +73,7 @@
<additionalClasspathElements>
<additionalClasspathElement>${maven.jdbc.driver.jar}</additionalClasspathElement>
</additionalClasspathElements>
<argLine>-javaagent:${settings.localRepository}/org/apache/openjpa/openjpa/${version.org.apache.openjpa}/openjpa-${version.org.apache.openjpa}.jar</argLine>
</configuration>
</plugin>
</plugins>
Expand Down Expand Up @@ -161,22 +161,12 @@
<scope>test</scope>
</dependency>

<!-- Hibernate -->
<!--~~(No version provided)~~>--><dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
Expand All @@ -193,12 +183,18 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jboss.narayana.jta</groupId>
<artifactId>narayana-jta</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class SessionInfo implements PersistentSession {

private @Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="sessionInfoIdSeq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="sessionInfoIdSeq")
Long id;

@Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class WorkItemInfo implements PersistentWorkItem {
private static final Logger logger = LoggerFactory.getLogger(WorkItemInfo.class);

@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator="workItemInfoIdSeq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="workItemInfoIdSeq")
private Long workItemId;

@Version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package org.drools.persistence.jpa;

import java.util.concurrent.atomic.AtomicInteger;

import jakarta.persistence.OptimisticLockException;
import org.drools.commands.impl.AbstractInterceptor;
import org.kie.api.runtime.Executable;
import org.kie.api.runtime.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.persistence.OptimisticLockException;
import java.util.concurrent.atomic.AtomicInteger;

/**
* ExecutableInterceptor that is capable of retrying command execution. It is intended to retry only if right exception
* has been thrown. By default it will look for <code>org.hibernate.StaleObjectStateException</code> and only
Expand Down Expand Up @@ -58,14 +58,14 @@ public class OptimisticLockRetryInterceptor extends AbstractInterceptor {
private static final ThreadLocal<AtomicInteger> invocationsCounter = new ThreadLocal<>();

public OptimisticLockRetryInterceptor() {
String clazz = System.getProperty("org.kie.optlock.exclass", "org.hibernate.StaleObjectStateException");
String clazz = System.getProperty("org.kie.optlock.exclass", "org.apache.openjpa.persistence.OptimisticLockException");
try {
targetExceptionClass = Class.forName(clazz);
} catch (ClassNotFoundException e) {
logger.error("Optimistic locking exception class not found {}", clazz, e);
}

clazz = System.getProperty("org.kie.constraint.exclass", "org.hibernate.exception.ConstraintViolationException");
clazz = System.getProperty("org.kie.constraint.exclass", "org.apache.openjpa.util.InvalidStateException");
try {
targetConstraintViolationExceptionClass = Class.forName(clazz);
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd">

<persistence-unit name="org.drools.persistence.jpa" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>jdbc/testDS1</jta-data-source>
<class>org.drools.persistence.info.SessionInfo</class>
<class>org.drools.persistence.info.WorkItemInfo</class>
Expand All @@ -34,19 +34,7 @@
<class>org.drools.persistence.jta.TransactionTestObject</class>

<properties>
<property name="hibernate.max_fetch_depth" value="3"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="false" />

<property name="hibernate.dialect" value="${maven.hibernate.dialect}"/>
<property name="hibernate.default_schema" value="${maven.jdbc.schema}"/>

<!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->
<property name="hibernate.id.new_generator_mappings" value="false" />

<!-- The following line is what's used in Hibernate 4 instead of a TransactionManagerLookup class -->
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />
<property name="hibernate.connection.release_mode" value="after_transaction"/>
<property name="jakarta.persistence.schema-generation.database.action" value="create"/>
</properties>

</persistence-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.drools.persistence.api.TransactionManager;
import org.drools.persistence.jpa.JpaPersistenceContextManager;
import org.drools.persistence.util.DroolsPersistenceUtil;
import org.hibernate.TransientObjectException;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -150,7 +149,7 @@ public void showingTransactionTestObjectsNeedTransactions() throws Exception {
tx.commit();
}
catch( Exception e ) {
if( e instanceof RollbackException || e.getCause() instanceof TransientObjectException ) {
if ( e instanceof RollbackException ) {
rollBackExceptionthrown = true;

if( tx.getStatus() == 1 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class TransactionTestObject implements Serializable {
private static final long serialVersionUID = 8991032325499307158L;

@Id
@GeneratedValue(strategy=GenerationType.AUTO, generator="txTestIdSeq")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="txTestIdSeq")
@Column(name="ID")
private Long id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
*/
package org.drools.persistence.map.impl;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import jakarta.persistence.EntityManagerFactory;
import org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy;
import org.drools.persistence.jta.JtaTransactionManager;
import org.drools.persistence.util.DroolsPersistenceUtil;
Expand All @@ -34,11 +39,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import jakarta.persistence.EntityManagerFactory;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

import static org.drools.persistence.util.DroolsPersistenceUtil.DROOLS_PERSISTENCE_UNIT_NAME;
import static org.drools.persistence.util.DroolsPersistenceUtil.OPTIMISTIC_LOCKING;
import static org.drools.persistence.util.DroolsPersistenceUtil.PESSIMISTIC_LOCKING;
Expand Down Expand Up @@ -115,7 +115,7 @@ protected long getSavedSessionsCount() {
if( useTransactions ) {
transactionOwner = txm.begin();
}
long savedSessionsCount = emf.createEntityManager().createQuery( "FROM SessionInfo" ).getResultList().size();
long savedSessionsCount = emf.createEntityManager().createQuery( "SELECT DISTINCT id FROM SessionInfo AS id" ).getResultList().size();
if( useTransactions ) {
txm.commit(transactionOwner);
}
Expand Down
38 changes: 20 additions & 18 deletions drools-traits/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

<!-- These are properties used in the database profiles. Some of them must be initialized
to be empty so that Maven applies their values via filtering to the resources. -->
<maven.hibernate.dialect>org.hibernate.dialect.H2Dialect</maven.hibernate.dialect>
<maven.datasource.classname>org.h2.jdbcx.JdbcDataSource</maven.datasource.classname>
<maven.jdbc.driver.class>org.h2.Driver</maven.jdbc.driver.class>
<maven.jdbc.db.name/>
Expand Down Expand Up @@ -128,6 +127,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>test</scope>
</dependency>
<dependency><!-- For unit test logging: configure in src/test/resources/logback-test.xml -->
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
Expand Down Expand Up @@ -156,23 +160,12 @@
<artifactId>jboss-transaction-spi-jakarta</artifactId>
<scope>test</scope>
</dependency>

<!-- Hibernate -->
<!--~~(No version provided)~~>--><dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.smallrye</groupId>
<artifactId>jandex</artifactId>
Expand Down Expand Up @@ -200,10 +193,9 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>


</dependencies>


<build>
<resources>
<resource>
Expand All @@ -215,6 +207,16 @@
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${settings.localRepository}/org/apache/openjpa/openjpa/${version.org.apache.openjpa}/openjpa-${version.org.apache.openjpa}.jar</argLine>
</configuration>
</plugin>
</plugins>

<testResources>
<testResource>
<directory>src/test/resources</directory>
Expand Down
Loading

0 comments on commit d26490d

Please sign in to comment.