Skip to content

Commit

Permalink
HSEARCH-5008 Upgrade to Hibernate ORM 6.4.0.Final
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Nov 23, 2023
1 parent a8bb722 commit 9e9e9ce
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 68 deletions.
2 changes: 1 addition & 1 deletion build/parents/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

<!-- >>> ORM 6 with Jakarta Persistence -->
<!-- IMPORTANT: Make sure that version.jakarta.persistence aligns with the imported version! -->
<version.org.hibernate.orm>6.3.1.Final</version.org.hibernate.orm>
<version.org.hibernate.orm>6.4.0.Final</version.org.hibernate.orm>

<javadoc.org.hibernate.orm.url>https://docs.jboss.org/hibernate/orm/${parsed-version.org.hibernate.orm.majorVersion}.${parsed-version.org.hibernate.orm.minorVersion}/javadocs/</javadoc.org.hibernate.orm.url>
<documentation.org.hibernate.orm.url>https://docs.jboss.org/hibernate/orm/${parsed-version.org.hibernate.orm.majorVersion}.${parsed-version.org.hibernate.orm.minorVersion}/userguide/html_single/Hibernate_User_Guide.html</documentation.org.hibernate.orm.url>
Expand Down
9 changes: 2 additions & 7 deletions ci/dependency-update/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
// Also make sure to update the parameters in the parameters {} section of the pipeline.
Map settings() {
switch (env.DEPENDENCY_UPDATE_NAME) {
case 'orm6.3':
return [
updateProperties: ['version.org.hibernate.orm'],
onlyRunTestDependingOn: ['hibernate-search-mapper-orm'],
]
case 'orm6.4':
return [
updateProperties: ['version.org.hibernate.orm'],
Expand Down Expand Up @@ -100,7 +95,7 @@ pipeline {
parameters {
// choice parameter doesn't have a default, but the first value should be treated as a default, if it wasn't specified manually.
// Make sure tp update axis and settings() when adding new choice parameter.
choice(name: 'UPDATE_JOB', choices: ['all', 'orm6.3', 'orm6.4', 'lucene9.8','lucene9', 'lucene10', 'elasticsearch-latest'], description: 'Select which update jobs to run. `All` will include all configured update jobs.')
choice(name: 'UPDATE_JOB', choices: ['all', 'orm6.4', 'lucene9.8','lucene9', 'lucene10', 'elasticsearch-latest'], description: 'Select which update jobs to run. `All` will include all configured update jobs.')
string(name: 'ORM_REPOSITORY', defaultValue: '', description: 'Git URL to Hibernate ORM repository. If provided, Hibernate ORM will be built locally. Works only in pair with ORM_BRANCH. Provide an http repository URL rather than an ssh one.')
string(name: 'ORM_BRANCH', defaultValue: '', description: 'Hibernate ORM branch to build from. If provided, Hibernate ORM will be built locally. Works only in pair with ORM_REPOSITORY. Either a pull request ID or a branch name should be provided, but not both at the same time. Use branch if you want to build from a fork repository.')
string(name: 'ORM_PULL_REQUEST_ID', defaultValue: '', description: 'Hibernate ORM pull request id to build from. If provided, Hibernate ORM will be built locally. Works only in pair with ORM_REPOSITORY. Either a pull request ID or a branch name should be provided, but not both at the same time.')
Expand Down Expand Up @@ -195,7 +190,7 @@ pipeline {
name 'DEPENDENCY_UPDATE_NAME'
// NOTE: Remember to update the settings() method above when changing this.
// And also add a new choice parameter in the parameters {} section of the pipeline
values 'orm6.3', 'orm6.4', 'lucene9.8','lucene9', 'lucene10', 'elasticsearch-latest'
values 'orm6.4', 'lucene9.8','lucene9', 'lucene10', 'elasticsearch-latest'
}
}
stages {
Expand Down
12 changes: 0 additions & 12 deletions ci/dependency-update/rules-orm6.3.xml

This file was deleted.

7 changes: 5 additions & 2 deletions documentation/src/main/asciidoc/migration/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Hibernate Search {hibernateSearchVersion} now requires:
- JDK 11 or later;
- Lucene 9 for its Lucene backend;
- Elasticsearch 7.10+ or OpenSearch 1.3+ for its Elasticsearch backend;
- Hibernate ORM 6.3.x for the Hibernate ORM integration.
- Hibernate ORM 6.4.x for the Hibernate ORM integration.

Regarding the Hibernate ORM requirements, when migrating from previous versions of Hibernate Search:

Expand All @@ -54,6 +54,9 @@ to artifacts ending with `-orm6` (e.g. `hibernate-search-mapper-orm-orm6`).
Just remove the `-orm6` suffix from the dependency coordinates
(e.g. use `hibernate-search-mapper-orm` instead)
when you upgrade to this version of Hibernate Search.
+
Then, https://github.com/hibernate/hibernate-orm/blob/6.4/migration-guide.adoc[migrate to Hibernate ORM 6.4]
at the same time you upgrade to this version of Hibernate Search.
If your application uses Hibernate ORM 6.2::
You need to https://github.com/hibernate/hibernate-orm/blob/6.3/migration-guide.adoc[migrate to Hibernate ORM 6.3] first
before upgrading to this version of Hibernate Search.
Expand All @@ -62,7 +65,7 @@ Then follow the instructions for "If your application uses Hibernate ORM 6.3" ab
If your application uses Hibernate ORM 5.6::
You need to migrate to Hibernate ORM 6.3 first
before upgrading to this version of Hibernate Search;
see https://github.com/hibernate/hibernate-orm/wiki/Migration-Guides/[Hibernate ORM migration guides]
see https://hibernate.org/orm/documentation/migrate/[Hibernate ORM migration guides]
and https://docs.jboss.org/hibernate/search/6.2/reference/en-US/html_single/#other-integrations-orm6[this guide for using Hibernate ORM 6.x with Hibernate Search 6.2].
+
Then follow the instructions for "If your application uses Hibernate ORM 6.3" above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.hibernate.search.integrationtest.jakarta.batch.util;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with;

import java.lang.invoke.MethodHandles;
import java.util.List;
Expand Down Expand Up @@ -116,27 +117,25 @@ public static JobExecution waitForTermination(JobExecution jobExecution)
}

public static <T> int nbDocumentsInIndex(EntityManagerFactory emf, Class<T> clazz) {
try ( Session session = emf.unwrap( SessionFactory.class ).openSession() ) {
return with( emf ).applyNoTransaction( session -> {
SearchSession searchSession = Search.session( session );
searchSession.workspace().refresh();
long totalHitCount = searchSession.search( clazz ).where( f -> f.matchAll() ).fetchTotalHitCount();
return Math.toIntExact( totalHitCount );
}
} );
}

public static <T> List<T> findIndexedResults(EntityManagerFactory emf, Class<T> clazz, String key, String value) {
SessionFactory sessionFactory = emf.unwrap( SessionFactory.class );
try ( Session session = sessionFactory.openSession() ) {
return find( session, clazz, key, value );
}
return with( sessionFactory )
.applyNoTransaction( session -> find( session, clazz, key, value ) );
}

public static <T> List<T> findIndexedResultsInTenant(EntityManagerFactory emf, Class<T> clazz, String key, String value,
String tenantId) {
SessionFactory sessionFactory = emf.unwrap( SessionFactory.class );
try ( Session session = sessionFactory.withOptions().tenantIdentifier( tenantId ).openSession() ) {
return find( session, clazz, key, value );
}
return with( sessionFactory, tenantId )
.applyNoTransaction( session -> find( session, clazz, key, value ) );
}

private static <T> List<T> find(Session session, Class<T> clazz, String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hibernate.search.util.impl.integrationtest.mapper.orm.OrmUtils.with;

import java.util.List;
import java.util.function.Consumer;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.search.integrationtest.mapper.orm.realbackend.testsupport.BackendConfigurations;
import org.hibernate.search.mapper.orm.Search;
Expand Down Expand Up @@ -79,28 +78,28 @@ void multiTenancyStrategy_none() {
}

private void checkMultitenancy() {
withinTransaction( TENANT_ID_1, session -> {
with( sessionFactory, TENANT_ID_1 ).runInTransaction( session -> {
IndexedEntity entity = new IndexedEntity();
entity.id = 1;
entity.text = TENANT_TEXT_1;
session.persist( entity );
} );
withinTransaction( TENANT_ID_2, session -> {
with( sessionFactory, TENANT_ID_2 ).runInTransaction( session -> {
IndexedEntity entity = new IndexedEntity();
entity.id = 1;
entity.text = TENANT_TEXT_2;
session.persist( entity );
} );

withinSession( TENANT_ID_1, session -> {
with( sessionFactory, TENANT_ID_1 ).runInTransaction( session -> {
List<IndexedEntity> entities = Search.session( session )
.search( IndexedEntity.class )
.where( f -> f.matchAll() )
.fetchAllHits();

assertThat( entities ).extracting( "text" ).containsExactly( TENANT_TEXT_1 );
} );
withinSession( TENANT_ID_2, session -> {
with( sessionFactory, TENANT_ID_2 ).runInTransaction( session -> {
List<IndexedEntity> entities = Search.session( session )
.search( IndexedEntity.class )
.where( f -> f.matchAll() )
Expand All @@ -110,21 +109,6 @@ private void checkMultitenancy() {
} );
}

private void withinTransaction(String tenantId, Consumer<Session> action) {
withinSession( tenantId, (session) -> {
session.beginTransaction();
action.accept( session );
session.getTransaction().commit();
session.clear();
} );
}

private void withinSession(String tenantId, Consumer<Session> action) {
try ( Session session = sessionFactory.withOptions().tenantIdentifier( tenantId ).openSession() ) {
action.accept( session );
}
}

@Entity(name = IndexedEntity.NAME)
@Indexed(index = IndexedEntity.NAME)
public static final class IndexedEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ Book.INDEX, targetTenantId(), DocumentCommitStrategy.NONE, DocumentRefreshStrate
@Test
void reuseSearchSessionAfterOrmSessionIsClosed_createMassIndexer() {
Session session = sessionFactory.withOptions()
.tenantIdentifier( targetTenantId() )
.tenantIdentifier( (Object) targetTenantId() )
.openSession();
SearchSession searchSession = Search.session( session );
// a SearchSession instance is created lazily,
Expand All @@ -528,7 +528,7 @@ void reuseSearchSessionAfterOrmSessionIsClosed_createMassIndexer() {
@Test
void lazyCreateSearchSessionAfterOrmSessionIsClosed_createMassIndexer() {
Session session = sessionFactory.withOptions()
.tenantIdentifier( targetTenantId() )
.tenantIdentifier( (Object) targetTenantId() )
.openSession();
// Search session is not created, since we don't use it
SearchSession searchSession = Search.session( session );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private List<? extends EntityReference> searchReferences(String tenantId, Clock[
}
}

private Session openSessionWithTenantId(String tid) {
private Session openSessionWithTenantId(Object tid) {
return sessionFactory.withOptions().tenantIdentifier( tid ).openSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void purgeAll(Class<?> entityType, String tenantId) throws IOException {
session.close();
}

private Session openSessionWithTenantId(String tenantId) {
private Session openSessionWithTenantId(Object tenantId) {
return getSessionFactory().withOptions().tenantIdentifier( tenantId ).openSession();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static Session openSession(EntityManagerFactory entityManagerFactory, Str
@SuppressWarnings("rawtypes")
SessionBuilder builder = sessionFactory.withOptions();
if ( StringHelper.isNotEmpty( tenantId ) ) {
builder.tenantIdentifier( tenantId );
builder.tenantIdentifier( (Object) tenantId );
}
Session session = builder.openSession();
// We don't need to write to the database
Expand All @@ -69,7 +69,7 @@ public static StatelessSession openStatelessSession(EntityManagerFactory entityM
@SuppressWarnings("rawtypes")
StatelessSessionBuilder builder = sessionFactory.withStatelessOptions();
if ( StringHelper.isNotEmpty( tenantId ) ) {
builder.tenantIdentifier( tenantId );
builder.tenantIdentifier( (Object) tenantId );
}
return builder.openStatelessSession();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public long countAbortedEvents() {
public long countAbortedEvents(String tenantId) {
checkTenant( tenantId );

try ( Session session = sessionFactory.withOptions().tenantIdentifier( tenantId ).openSession() ) {
try ( Session session = sessionFactory.withOptions().tenantIdentifier( (Object) tenantId ).openSession() ) {
return transactionHelper.inTransaction( (SharedSessionContractImplementor) session, () -> {
Query<Long> query = session.createQuery( COUNT_EVENTS_WITH_STATUS, Long.class );
query.setParameter( "status", OutboxEvent.Status.ABORTED );
Expand All @@ -91,7 +91,7 @@ public int reprocessAbortedEvents() {
public int reprocessAbortedEvents(String tenantId) {
checkTenant( tenantId );

try ( Session session = sessionFactory.withOptions().tenantIdentifier( tenantId ).openSession() ) {
try ( Session session = sessionFactory.withOptions().tenantIdentifier( (Object) tenantId ).openSession() ) {
return transactionHelper.inTransaction( (SharedSessionContractImplementor) session, () -> {
MutationQuery query = session.createMutationQuery( UPDATE_EVENTS_WITH_STATUS );
query.setParameter( "status", OutboxEvent.Status.ABORTED );
Expand All @@ -118,7 +118,7 @@ public int clearAllAbortedEvents() {
public int clearAllAbortedEvents(String tenantId) {
checkTenant( tenantId );

try ( Session session = sessionFactory.withOptions().tenantIdentifier( tenantId ).openSession() ) {
try ( Session session = sessionFactory.withOptions().tenantIdentifier( (Object) tenantId ).openSession() ) {
return transactionHelper.inTransaction( (SharedSessionContractImplementor) session, () -> {
MutationQuery query = session.createMutationQuery( DELETE_EVENTS_WITH_STATUS );
query.setParameter( "status", OutboxEvent.Status.ABORTED );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
public final class SessionHelper {

private final SessionFactoryImplementor sessionFactory;
private final String tenantId;
private final Object tenantId;

public SessionHelper(SessionFactoryImplementor sessionFactory, String tenantId) {
public SessionHelper(SessionFactoryImplementor sessionFactory, Object tenantId) {
this.sessionFactory = sessionFactory;
this.tenantId = tenantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public PojoMassIdentifierLoader createIdentifierLoader(PojoMassIndexingIdentifie
HibernateOrmQueryLoader<E, I> typeQueryLoader = createQueryLoader( typeContexts );
SharedSessionContractImplementor session = (SharedSessionContractImplementor) sessionFactory
.withStatelessOptions()
.tenantIdentifier( context.tenantIdentifier() )
.tenantIdentifier( (Object) context.tenantIdentifier() )
.openStatelessSession();
try {
PojoMassIdentifierSink<I> sink = context.createSink();
Expand All @@ -198,7 +198,7 @@ public PojoMassEntityLoader<I> createEntityLoader(PojoMassIndexingEntityLoadingC
HibernateOrmQueryLoader<E, ?> typeQueryLoader = createQueryLoader( typeContexts );
SessionImplementor session = (SessionImplementor) sessionFactory
.withOptions()
.tenantIdentifier( context.tenantIdentifier() )
.tenantIdentifier( (Object) context.tenantIdentifier() )
.openSession();
try {
session.setHibernateFlushMode( FlushMode.MANUAL );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

class NativePersistenceRunner implements PersistenceRunner<Session, Transaction> {
private final SessionFactory sessionFactory;
private final String tenantId;
private final Object tenantId;

NativePersistenceRunner(SessionFactory sessionFactory, String tenantId) {
NativePersistenceRunner(SessionFactory sessionFactory, Object tenantId) {
this.sessionFactory = sessionFactory;
this.tenantId = tenantId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static PersistenceRunner<Session, Transaction> with(SessionFactory sessio
return with( sessionFactory, null );
}

public static PersistenceRunner<Session, Transaction> with(SessionFactory sessionFactory, String tenantId) {
public static PersistenceRunner<Session, Transaction> with(SessionFactory sessionFactory, Object tenantId) {
return new NativePersistenceRunner( sessionFactory, tenantId );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import org.jboss.logging.Logger;

public class H2LazyMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider
public class H2LazyMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider<String>
implements Stoppable {

private static final Logger log = Logger.getLogger( H2LazyMultiTenantConnectionProvider.class.getName() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public interface FullTextSharedSessionBuilder extends SharedSessionBuilder {
@Override
FullTextSession openSession();

@Deprecated(forRemoval = true)
@Override
FullTextSharedSessionBuilder tenantIdentifier(String tenantIdentifier);

@Override
FullTextSharedSessionBuilder tenantIdentifier(Object tenantIdentifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ public FullTextSession openSession() {
return Search.getFullTextSession( builder.openSession() );
}

@Deprecated(forRemoval = true)
@Override
public FullTextSharedSessionBuilder tenantIdentifier(String tenantIdentifier) {
builder.tenantIdentifier( tenantIdentifier );
return this;
}

@Override
public FullTextSharedSessionBuilder tenantIdentifier(Object tenantIdentifier) {
builder.tenantIdentifier( tenantIdentifier );
return this;
}

@Override
public FullTextSharedSessionBuilder clearEventListeners() {
builder.clearEventListeners();
Expand Down

0 comments on commit 9e9e9ce

Please sign in to comment.