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 Jul 3, 2023
1 parent a28971e commit 632db7e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 78 deletions.
Original file line number Diff line number Diff line change
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 );
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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 @@ -145,25 +145,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 scroll() {
public ScrollableResultsImplementor<R> scroll() {
return scroll( ScrollMode.FORWARD_ONLY );
}

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

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

extractQueryOptions();
}
Expand All @@ -204,6 +198,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 @@ -227,7 +226,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 @@ -328,8 +327,4 @@ private static int hintValueToInteger(Object value) {
}
}

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

}
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,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 with 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 @@ -279,13 +279,13 @@
and to our own explicit dependencies in the relevant artifacts.
-->
<version.io.smallrye.jandex>3.0.5</version.io.smallrye.jandex>
<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.transaction-api>2.0.0</version.jakarta.transaction-api>
<version.jakarta.interceptor-api>2.0.1</version.jakarta.interceptor-api>
<version.jakarta.enterprise>3.0.1</version.jakarta.enterprise>
<version.jakarta.xml.bind>4.0.0</version.jakarta.xml.bind>
<version.net.bytebuddy.orm6>1.12.18</version.net.bytebuddy.orm6>
<version.jakarta.xml.bind>3.0.1</version.jakarta.xml.bind>
<version.net.bytebuddy.orm6>1.12.7</version.net.bytebuddy.orm6>

<!-- >>> JSR 352 -->
<version.jakarta.batch>2.1.1</version.jakarta.batch>
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,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 @@ -127,11 +132,6 @@ public ScrollableResultsImplementor scroll() {
Search5ScrollHitExtractor.INSTANCE );
}

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

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

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

extractQueryOptions();
}
Expand Down Expand Up @@ -202,11 +202,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 @@ -253,20 +258,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 @@ -284,7 +283,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 632db7e

Please sign in to comment.