Skip to content

Commit

Permalink
HSEARCH-4465 Upgrade to Hibernate ORM 6.0.0.CR1
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Oct 6, 2022
1 parent 0a4f367 commit 55bde0e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 80 deletions.
Expand Up @@ -50,6 +50,9 @@ public void entityGraphHint(EntityGraphHint<?> entityGraphHint, boolean replaceE
else if ( replaceExisting ) {
entityGraphHints.clear();
}
if ( entityGraphHint == null ) {
return;
}
this.entityGraphHints.add( entityGraphHint );
}
}
Expand Up @@ -23,7 +23,7 @@
import org.hibernate.mapping.Value;
import org.hibernate.property.access.spi.Getter;

@SuppressWarnings( "unchecked" ) // Hibernate ORM gives us raw types, we must make do.
@SuppressWarnings( "unchecked" ) // Hibernate Commons annotations gives us wildcard types, we must make do.
public class HibernateOrmBasicTypeMetadataProvider {

public static HibernateOrmBasicTypeMetadataProvider create(Metadata metadata) {
Expand Down Expand Up @@ -161,7 +161,7 @@ else if ( value instanceof org.hibernate.mapping.Array ) {
else if ( value instanceof org.hibernate.mapping.Map ) {
org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) value;
return HibernateOrmTypeModelFactory.map(
map.getCollectionType().getReturnedClass(),
(Class<? extends Map<?, ?>>) map.getCollectionType().getReturnedClass(),
/*
* Do not let ORM confuse you: getKey() doesn't return the value of the map key,
* but the value of the foreign key to the targeted entity...
Expand All @@ -174,7 +174,7 @@ else if ( value instanceof org.hibernate.mapping.Map ) {
else if ( value instanceof org.hibernate.mapping.Collection ) {
org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection) value;
return HibernateOrmTypeModelFactory.collection(
collection.getCollectionType().getReturnedClass(),
(Class<? extends Collection<?>>) collection.getCollectionType().getReturnedClass(),
collectValue( metadataProviderBuilder, collection.getElement() )
);
}
Expand Down
Expand Up @@ -127,7 +127,7 @@ public HibernateOrmSearchQueryAdapter<R> setHint(String hintName, Object value)
case HibernateOrmSearchQueryHints.JAKARTA_FETCHGRAPH:
case HibernateOrmSearchQueryHints.JAVAX_LOADGRAPH:
case HibernateOrmSearchQueryHints.JAKARTA_LOADGRAPH:
applyEntityGraphQueryHint( hintName, hintValueToEntityGraph( value ) );
applyEntityGraphHint( hintName, value );
break;
default:
log.ignoringUnrecognizedQueryHint( hintName );
Expand All @@ -143,25 +143,19 @@ public HibernateOrmSearchQueryAdapter<R> setTimeout(int timeout) {
}

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("rawtypes")
public HibernateOrmSearchQueryAdapter<R> applyGraph(RootGraph graph, GraphSemantic semantic) {
loadingOptions.entityGraphHint( new EntityGraphHint<>( graph, semantic ), true );
applyGraph( (RootGraphImplementor) graph, semantic );
return this;
}

@Override
protected void applyEntityGraphQueryHint(String hintName, RootGraphImplementor<?> entityGraph) {
GraphSemantic graphSemantic = GraphSemantic.fromJpaHintName( hintName );
this.applyGraph( entityGraph, graphSemantic );
}

@Override
public ScrollableResultsImplementor<R> scroll() {
return scroll( ScrollMode.FORWARD_ONLY );
}

@Override
public ScrollableResultsImplementor<R> scroll(ScrollMode scrollMode) {
protected ScrollableResultsImplementor<R> doScroll(ScrollMode scrollMode) {
if ( !ScrollMode.FORWARD_ONLY.equals( scrollMode ) ) {
throw log.canOnlyUseScrollWithScrollModeForwardsOnly( scrollMode );
}
Expand All @@ -187,8 +181,8 @@ protected List<R> doList() {
}

@Override
protected void beforeQuery(boolean requiresTxn) {
super.beforeQuery( requiresTxn );
protected void beforeQuery() {
super.beforeQuery();

extractQueryOptions();
}
Expand All @@ -202,6 +196,11 @@ private void extractQueryOptions() {
if ( queryTimeout != null ) {
delegate.failAfter( queryTimeout, TimeUnit.SECONDS );
}
EntityGraphHint<?> entityGraphHint = null;
if ( queryOptions.getGraph() != null ) {
entityGraphHint = new EntityGraphHint<>( queryOptions.getGraph(), queryOptions.getSemantic() );
}
loadingOptions.entityGraphHint( entityGraphHint, true );
}

//-------------------------------------------------------------
Expand All @@ -225,7 +224,7 @@ public QueryParameterBindings getParameterBindings() {
}

@Override
protected QueryParameterBindings getQueryParameterBindings() {
public QueryParameterBindings getQueryParameterBindings() {
// parameters not supported in Hibernate Search queries
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
Expand Down Expand Up @@ -321,8 +320,4 @@ private static int hintValueToInteger(Object value) {
}
}

private static RootGraphImplementor<?> hintValueToEntityGraph(Object value) {
return (RootGraphImplementor<?>) value;
}

}
8 changes: 4 additions & 4 deletions pom.xml
Expand Up @@ -274,12 +274,12 @@
when the versions start diverging, thanks to the maven-enforcer-plugin
and to our own explicit dependencies in the relevant artifacts.
-->
<version.org.jboss.jandex>2.2.3.Final</version.org.jboss.jandex>
<version.org.jboss.jandex>2.4.2.Final</version.org.jboss.jandex>
<version.org.hibernate.commons.annotations>${version.org.hibernate.commons.annotations.orm6}</version.org.hibernate.commons.annotations>
<version.net.bytebuddy>${version.net.bytebuddy.orm6}</version.net.bytebuddy>

<!-- >>> ORM 6 / Jakarta Persistence -->
<version.org.hibernate.orm>6.0.0.Beta3</version.org.hibernate.orm>
<version.org.hibernate.orm>6.0.0.CR1</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>
<!-- These version must be kept in sync with the version of the dependency in Hibernate ORM 6.
Expand All @@ -288,11 +288,11 @@
when the versions start diverging, thanks to the maven-enforcer-plugin
and to our own explicit dependencies in the relevant artifacts.
-->
<version.org.hibernate.commons.annotations.orm6>5.1.3.Final</version.org.hibernate.commons.annotations.orm6>
<version.org.hibernate.commons.annotations.orm6>6.0.0.CR1</version.org.hibernate.commons.annotations.orm6>
<version.jakarta.persistence>3.0.0</version.jakarta.persistence>
<version.jakarta.enterprise>3.0.1</version.jakarta.enterprise>
<version.jakarta.xml.bind>3.0.1</version.jakarta.xml.bind>
<version.net.bytebuddy.orm6>1.12.9</version.net.bytebuddy.orm6>
<version.net.bytebuddy.orm6>1.12.7</version.net.bytebuddy.orm6>

<!-- >>> JSR 352 -->
<version.jakarta.batch>2.1.1</version.jakarta.batch>
Expand Down
Expand Up @@ -10,7 +10,6 @@

import jakarta.persistence.EntityManager;

import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Interceptor;
import org.hibernate.Session;
import org.hibernate.SharedSessionBuilder;
Expand Down Expand Up @@ -40,10 +39,6 @@ public interface FullTextSharedSessionBuilder extends SharedSessionBuilder {
@Override
FullTextSharedSessionBuilder autoClose();

@Deprecated
@Override
FullTextSharedSessionBuilder flushBeforeCompletion();

@Deprecated
@Override
FullTextSharedSessionBuilder transactionContext();
Expand All @@ -57,21 +52,13 @@ public interface FullTextSharedSessionBuilder extends SharedSessionBuilder {
@Override
FullTextSharedSessionBuilder connection(Connection connection);

@Deprecated
@Override
FullTextSharedSessionBuilder connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode);

@Override
FullTextSharedSessionBuilder autoJoinTransactions(boolean autoJoinTransactions);

@Deprecated
@Override
FullTextSharedSessionBuilder autoClose(boolean autoClose);

@Deprecated
@Override
FullTextSharedSessionBuilder flushBeforeCompletion(boolean flushBeforeCompletion);

@Override
FullTextSession openSession();

Expand Down
Expand Up @@ -9,7 +9,6 @@
import java.sql.Connection;
import java.util.TimeZone;

import org.hibernate.ConnectionReleaseMode;
import org.hibernate.FlushMode;
import org.hibernate.Interceptor;
import org.hibernate.SessionBuilder;
Expand Down Expand Up @@ -63,13 +62,6 @@ public FullTextSharedSessionBuilder autoClose() {
return this;
}

@Deprecated
@Override
public FullTextSharedSessionBuilder flushBeforeCompletion() {
builder.flushBeforeCompletion();
return this;
}

@Deprecated
@Override
public FullTextSharedSessionBuilder transactionContext() {
Expand All @@ -95,13 +87,6 @@ public FullTextSharedSessionBuilder connection(Connection connection) {
return this;
}

@Deprecated
@Override
public FullTextSharedSessionBuilder connectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
builder.connectionReleaseMode( connectionReleaseMode );
return this;
}

@Override
public FullTextSharedSessionBuilder autoJoinTransactions(boolean autoJoinTransactions) {
builder.autoJoinTransactions( autoJoinTransactions );
Expand All @@ -115,13 +100,6 @@ public FullTextSharedSessionBuilder autoClose(boolean autoClose) {
return this;
}

@Deprecated
@Override
public FullTextSharedSessionBuilder flushBeforeCompletion(boolean flushBeforeCompletion) {
builder.flushBeforeCompletion( flushBeforeCompletion );
return this;
}

@Override
public FullTextSession openSession() {
return Search.getFullTextSession( builder.openSession() );
Expand Down
Expand Up @@ -14,10 +14,6 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.QueryTimeoutException;

import org.hibernate.HibernateException;
import org.hibernate.LockMode;
Expand Down Expand Up @@ -53,6 +49,10 @@
import org.hibernate.search.util.common.SearchTimeoutException;
import org.hibernate.transform.ResultTransformer;

import jakarta.persistence.FlushModeType;
import jakarta.persistence.LockModeType;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.QueryTimeoutException;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
Expand Down Expand Up @@ -116,6 +116,11 @@ public List getResultList() {

@Override
public ScrollableResultsImplementor scroll() {
return scroll( ScrollMode.FORWARD_ONLY );
}

@Override
protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) {
extractQueryOptions();
SearchScroll<?> scroll = hSearchQuery.scroll( fetchSize != null ? fetchSize : 100 );
Integer maxResults = hSearchQuery.maxResults();
Expand All @@ -124,11 +129,6 @@ public ScrollableResultsImplementor scroll() {
Search5ScrollHitExtractor.INSTANCE );
}

@Override
public ScrollableResultsImplementor scroll(ScrollMode scrollMode) {
return scroll();
}

@Override
public List list() {
try {
Expand All @@ -149,8 +149,8 @@ protected List doList() {
}

@Override
protected void beforeQuery(boolean requiresTxn) {
super.beforeQuery( requiresTxn );
protected void beforeQuery() {
super.beforeQuery();

extractQueryOptions();
}
Expand Down Expand Up @@ -199,11 +199,16 @@ public int doGetResultSize() {
}

@Override
public FullTextQueryImpl applyGraph(RootGraph graph, GraphSemantic semantic) {
entityGraphHints.add( new EntityGraphHint<>( graph, semantic ) );
public FullTextQuery applyGraph(RootGraph graph, GraphSemantic semantic) {
applyGraph( (RootGraphImplementor) graph, semantic );
return this;
}

@Override
protected void applyGraph(RootGraphImplementor<?> graph, GraphSemantic semantic) {
entityGraphHints.add( new EntityGraphHint<>( graph, semantic ) );
}

@Override
public FullTextQueryImpl setProjection(String... fields) {
hSearchQuery.projection( fields );
Expand Down Expand Up @@ -250,20 +255,14 @@ public FullTextQuery setHint(String hintName, Object value) {
case HibernateOrmSearchQueryHints.JAKARTA_FETCHGRAPH:
case HibernateOrmSearchQueryHints.JAVAX_LOADGRAPH:
case HibernateOrmSearchQueryHints.JAKARTA_LOADGRAPH:
applyEntityGraphQueryHint( hintName, hintValueToEntityGraph( value ) );
applyEntityGraphHint( hintName, hintValueToEntityGraph( value ) );
break;
default:
break;
}
return this;
}

@Override
protected void applyEntityGraphQueryHint(String hintName, RootGraphImplementor entityGraph) {
GraphSemantic graphSemantic = GraphSemantic.fromJpaHintName( hintName );
this.applyGraph( entityGraph, graphSemantic );
}

@Override
public Map<String, Object> getHints() {
return hints;
Expand All @@ -281,7 +280,7 @@ public QueryParameterBindings getParameterBindings() {
}

@Override
protected QueryParameterBindings getQueryParameterBindings() {
public QueryParameterBindings getQueryParameterBindings() {
// parameters not supported in Hibernate Search queries
return QueryParameterBindings.NO_PARAM_BINDINGS;
}
Expand Down

0 comments on commit 55bde0e

Please sign in to comment.