From ead2447524bd65cd452486940c31770a5fc8ba30 Mon Sep 17 00:00:00 2001 From: "nathan.xu" Date: Tue, 19 Oct 2021 23:28:36 -0400 Subject: [PATCH 1/7] HHH-14891 update JTS package name in user guide (Hibernate Spatial BasicTypes table in 'Domain Model' chapter) --- .../main/asciidoc/userguide/chapters/domain/basic_types.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc b/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc index a5544a778d..d12289de15 100644 --- a/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc +++ b/documentation/src/main/asciidoc/userguide/chapters/domain/basic_types.adoc @@ -87,7 +87,7 @@ Internally Hibernate uses a registry of basic types when it needs to resolve a s [cols="<.^,<.^,<.^,<.^",options="header",] |================================================================================================= |Hibernate type (org.hibernate.spatial package) |JDBC type |Java type |BasicTypeRegistry key(s) -|JTSGeometryType |depends on the dialect | com.vividsolutions.jts.geom.Geometry |jts_geometry, and the class names of Geometry and its subclasses +|JTSGeometryType |depends on the dialect | org.locationtech.jts.geom.Geometry |jts_geometry, and the class names of Geometry and its subclasses |GeolatteGeometryType |depends on the dialect | org.geolatte.geom.Geometry |geolatte_geometry, and the class names of Geometry and its subclasses |================================================================================================= From 2f52c8024c14a66cd3e83406f0c5b8180f986efa Mon Sep 17 00:00:00 2001 From: Higor Tavares <42852956+higortavares@users.noreply.github.com> Date: Tue, 19 Oct 2021 18:35:12 -0300 Subject: [PATCH 2/7] remove the commented code --- .../java/org/hibernate/cfg/BinderHelper.java | 129 ------------------ 1 file changed, 129 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java index a7f61dc18c..4dd9882d5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/BinderHelper.java @@ -111,135 +111,6 @@ public class BinderHelper { return clone; } -// This is sooooooooo close in terms of not generating a synthetic property if we do not have to (where property ref -// refers to a single property). The sticking point is cases where the `referencedPropertyName` come from subclasses -// or secondary tables. Part of the problem is in PersistentClass itself during attempts to resolve the referenced -// property; currently it only considers non-subclass and non-joined properties. Part of the problem is in terms -// of SQL generation. -// public static void createSyntheticPropertyReference( -// Ejb3JoinColumn[] columns, -// PersistentClass ownerEntity, -// PersistentClass associatedEntity, -// Value value, -// boolean inverse, -// Mappings mappings) { -// //associated entity only used for more precise exception, yuk! -// if ( columns[0].isImplicit() || StringHelper.isNotEmpty( columns[0].getMappedBy() ) ) return; -// int fkEnum = Ejb3JoinColumn.checkReferencedColumnsType( columns, ownerEntity, mappings ); -// PersistentClass associatedClass = columns[0].getPropertyHolder() != null ? -// columns[0].getPropertyHolder().getPersistentClass() : -// null; -// if ( Ejb3JoinColumn.NON_PK_REFERENCE == fkEnum ) { -// //find properties associated to a certain column -// Object columnOwner = findColumnOwner( ownerEntity, columns[0].getReferencedColumn(), mappings ); -// List properties = findPropertiesByColumns( columnOwner, columns, mappings ); -// -// if ( properties == null ) { -// //TODO use a ToOne type doing a second select -// StringBuilder columnsList = new StringBuilder(); -// columnsList.append( "referencedColumnNames(" ); -// for (Ejb3JoinColumn column : columns) { -// columnsList.append( column.getReferencedColumn() ).append( ", " ); -// } -// columnsList.setLength( columnsList.length() - 2 ); -// columnsList.append( ") " ); -// -// if ( associatedEntity != null ) { -// //overidden destination -// columnsList.append( "of " ) -// .append( associatedEntity.getEntityName() ) -// .append( "." ) -// .append( columns[0].getPropertyName() ) -// .append( " " ); -// } -// else { -// if ( columns[0].getPropertyHolder() != null ) { -// columnsList.append( "of " ) -// .append( columns[0].getPropertyHolder().getEntityName() ) -// .append( "." ) -// .append( columns[0].getPropertyName() ) -// .append( " " ); -// } -// } -// columnsList.append( "referencing " ) -// .append( ownerEntity.getEntityName() ) -// .append( " not mapped to a single property" ); -// throw new AnnotationException( columnsList.toString() ); -// } -// -// final String referencedPropertyName; -// -// if ( properties.size() == 1 ) { -// referencedPropertyName = properties.get(0).getName(); -// } -// else { -// // Create a synthetic (embedded composite) property to use as the referenced property which -// // contains all the properties mapped to the referenced columns. We need to make a shallow copy -// // of the properties to mark them as non-insertable/updatable. -// -// // todo : what if the columns all match with an existing component? -// -// StringBuilder propertyNameBuffer = new StringBuilder( "_" ); -// propertyNameBuffer.append( associatedClass.getEntityName().replace( '.', '_' ) ); -// propertyNameBuffer.append( "_" ).append( columns[0].getPropertyName() ); -// String syntheticPropertyName = propertyNameBuffer.toString(); -// //create an embeddable component -// -// //todo how about properties.size() == 1, this should be much simpler -// Component embeddedComp = columnOwner instanceof PersistentClass ? -// new Component( mappings, (PersistentClass) columnOwner ) : -// new Component( mappings, (Join) columnOwner ); -// embeddedComp.setEmbedded( true ); -// embeddedComp.setNodeName( syntheticPropertyName ); -// embeddedComp.setComponentClassName( embeddedComp.getOwner().getClassName() ); -// for (Property property : properties) { -// Property clone = BinderHelper.shallowCopy( property ); -// clone.setInsertable( false ); -// clone.setUpdateable( false ); -// clone.setNaturalIdentifier( false ); -// clone.setGeneration( property.getGeneration() ); -// embeddedComp.addProperty( clone ); -// } -// SyntheticProperty synthProp = new SyntheticProperty(); -// synthProp.setName( syntheticPropertyName ); -// synthProp.setNodeName( syntheticPropertyName ); -// synthProp.setPersistentClass( ownerEntity ); -// synthProp.setUpdateable( false ); -// synthProp.setInsertable( false ); -// synthProp.setValue( embeddedComp ); -// synthProp.setPropertyAccessorName( "embedded" ); -// ownerEntity.addProperty( synthProp ); -// //make it unique -// TableBinder.createUniqueConstraint( embeddedComp ); -// -// referencedPropertyName = syntheticPropertyName; -// } -// -// /** -// * creating the property ref to the new synthetic property -// */ -// if ( value instanceof ToOne ) { -// ( (ToOne) value ).setReferencedPropertyName( referencedPropertyName ); -// mappings.addUniquePropertyReference( ownerEntity.getEntityName(), referencedPropertyName ); -// } -// else if ( value instanceof Collection ) { -// ( (Collection) value ).setReferencedPropertyName( referencedPropertyName ); -// //not unique because we could create a mtm wo association table -// mappings.addPropertyReference( ownerEntity.getEntityName(), referencedPropertyName ); -// } -// else { -// throw new AssertionFailure( -// "Do a property ref on an unexpected Value type: " -// + value.getClass().getName() -// ); -// } -// mappings.addPropertyReferencedAssociation( -// ( inverse ? "inverse__" : "" ) + associatedClass.getEntityName(), -// columns[0].getPropertyName(), -// referencedPropertyName -// ); -// } -// } public static void createSyntheticPropertyReference( Ejb3JoinColumn[] columns, From 54ea27a4d586477ade662441b616dc11c2545c51 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Oct 2021 12:25:25 -0500 Subject: [PATCH 3/7] improve hibernate-core-jakarta build --- .../hibernate-core-jakarta.gradle | 227 +++++++++++++----- hibernate-core/hibernate-core.gradle | 15 +- 2 files changed, 175 insertions(+), 67 deletions(-) diff --git a/hibernate-core-jakarta/hibernate-core-jakarta.gradle b/hibernate-core-jakarta/hibernate-core-jakarta.gradle index e9b091c0c9..f2b1cf528e 100644 --- a/hibernate-core-jakarta/hibernate-core-jakarta.gradle +++ b/hibernate-core-jakarta/hibernate-core-jakarta.gradle @@ -5,8 +5,6 @@ * See the lgpl.txt file in the root directory or . */ -import org.apache.tools.ant.filters.ReplaceTokens - description = 'Hibernate O/RM implementation of the Jakarta Persistence specification' apply from: rootProject.file( 'gradle/published-java-module.gradle' ) @@ -88,86 +86,195 @@ dependencies { testCompile libraries.jboss_annotation_spec_jar } -jar { - mustRunAfter project(':hibernate-core').tasks.jar - mustRunAfter project(':hibernate-core').tasks.testJar +// we do not want the much of the normal java plugin's behavior +compileJava.enabled false +processResources.enabled false +compileTestJava.enabled false +processTestResources.enabled false +jar.enabled false + +ext { + transformedJarName = project(':hibernate-core').tasks.jar.archiveFileName.get().replaceAll( 'hibernate-core', 'hibernate-core-jakarta' ) + + unpackedTestDirRelative = 'tmp/unpack/test' + transformedTestDirRelative = 'classes/java/test' + + unpackedTestDir = "${buildDir}/${unpackedTestDirRelative}" + transformedTestDir = "${buildDir}/${transformedTestDirRelative}" + + baseTransformerArgs = [ + // "quiet" output + '-q', + '-tr', new File(getProjectDir().getParentFile(), 'rules/jakarta-renames.properties').path, + '-tv', new File(getProjectDir().getParentFile(), 'rules/jakarta-versions.properties').path, + '-td', new File(getProjectDir().getParentFile(), 'rules/jakarta-direct.properties').path, + ] +} + +task transformJar { + description 'Transforms the hibernate-core jar using the JakartaTransformer tool' + dependsOn project(':hibernate-core').tasks.jar - dependsOn project(':hibernate-core').tasks.testJar - def baseDir = project(':hibernate-core').buildDir - def baseJars = fileTree(baseDir).matching {include 'libs/*.jar' } - inputs.files(baseJars).skipWhenEmpty() - outputs.dir project.buildDir + mustRunAfter project(':hibernate-core').tasks.jar + + inputs.file project(':hibernate-core').tasks.jar.archiveFile + outputs.file "${buildDir}/libs/${transformedJarName}" + doLast { - new File(project.buildDir, "libs").mkdirs() - fileTree(project.buildDir).matching { include 'libs/*.jar' }.each { delete it } + def transformerArgs = [ + // source jar + project(':hibernate-core').tasks.jar.archiveFile.get(), + // target jar + file( "${buildDir}/libs/${transformedJarName}" ) + ] + ( project.baseTransformerArgs as ArrayList ) - baseJars.each { bundleJar -> - def sourceJarPath = baseDir.path + '/libs/' + bundleJar.name - println 'Initial bundle jar name [ ' + sourceJarPath + ' ]' + println 'Transformer options (main) :' + transformerArgs.each { + println ' [ ' + it + ' ]' + } - def finalBundleJarName = project.buildDir.path + '/libs/' + bundleJar.name.replaceAll( 'hibernate-core', 'hibernate-core-jakarta' ) - println 'Default jakarta final bundle jar name [ ' + finalBundleJarName + ' ]' - - def transformerArgs = [ - sourceJarPath, finalBundleJarName, - '-q', // quiet output - '-tr', new File(getProjectDir().getParentFile(), 'rules/jakarta-renames.properties').path, - '-tv', new File(getProjectDir().getParentFile(), 'rules/jakarta-versions.properties').path, - '-td', new File(getProjectDir().getParentFile(), 'rules/jakarta-direct.properties').path, - ] - - println 'Transformer options:' - transformerArgs.each { - println ' [ ' + it + ' ]' - } - - javaexec { - classpath configurations.jakartaeeTransformJars - main = 'org.eclipse.transformer.jakarta.JakartaTransformer' - args = transformerArgs - } + javaexec { + classpath configurations.jakartaeeTransformJars + main = 'org.eclipse.transformer.jakarta.JakartaTransformer' + args = transformerArgs } } } task unpackTestJar(type: Copy) { - dependsOn jar - fileTree(project.buildDir).matching { include 'libs/*-test.jar' }.each { - def outputDir = file("${buildDir}/unpacked/" + it.name) - from zipTree(it) - into outputDir + description 'Unpacks the hibernate-core test jar into a directory so we can transform it and replace token(s) in the test resources' + + dependsOn project(':hibernate-core').tasks.testJar + mustRunAfter project(':hibernate-core').tasks.testJar + + inputs.file project(':hibernate-core').tasks.testJar.archiveFile + outputs.dir project.unpackedTestDir + + from zipTree( project( ":hibernate-core" ).tasks.testJar.archiveFile ) + into project.unpackedTestDir + + // There are persistence.xml files referencing jar files through their absolute path so we + // have to replace 'hibernate-core' references in the path with 'hibernate-core-jakarta' + + filesMatching('**/*.xml') { + filter { line -> + line.replaceAll( 'hibernate-core/target', 'hibernate-core-jakarta/target' ) + } } + +// - commented out atm because this causes problems for the JakartaTransformer (doesn't everything?) +// filter { line -> +// line.replaceAll( 'hibernate-core/target', 'hibernate-core-jakarta/target' ) +// } + +// doLast { +// // replacing this text in the unpack dir causes problems for the JakartaTransformer (doesn't everything?) +// // - so we only do it in the transformed dir after the transformation happens. +// ant.replaceregexp(match:'hibernate-core', replace:'hibernate-core-jakarta', flags:'g', byline:true) { +// fileset(dir: "${project.unpackedTestDir}/bundles", includes: '**/*.xml') +// } +// } + } -task copyBundleResources (type: Copy) { +task transformTests { + description 'Transforms the hibernate-core tests using the JakartaTransformer tool' + dependsOn unpackTestJar - File unpackedDir = new File(project.buildDir, "libs/hibernate-core-jakarta-${project.version}-test.jar") - ext { - bundlesTargetDir = file( "${buildDir}/bundles" ) - bundleTokens = dbBundle[db] - ext.bundleTokens['buildDirName'] = buildDir.absolutePath + mustRunAfter unpackTestJar + + inputs.dir project.unpackedTestDir + outputs.dir project.transformedTestDir + + def transformedTestDirFile = file(project.transformedTestDir) + + doFirst { + println ":transformTests#doFirst : ${project.transformedTestDir} (exists? : ${transformedTestDirFile.exists()})" + + // JakartaTransformer expects that the output directory does not exist and + // also expects that the parent of the output directory does + if ( transformedTestDirFile.exists() ) { + def wasDeleteSuccessful = transformedTestDirFile.delete() + println ":unpackTestJar#doLast : deleting ${project.transformedTestDir} (successful? : ${wasDeleteSuccessful})" + + def wasMakeDirsSuccessful = transformedTestDirFile.parentFile.mkdirs() + println ":unpackTestJar#doLast : created ${transformedTestDirFile.parentFile.absolutePath} (successful? : ${wasMakeDirsSuccessful})" + } } - from file("${buildDir}/unpacked/${unpackedDir.name}/templates") - into ext.bundlesTargetDir - filter( ReplaceTokens, tokens: ext.bundleTokens) - doFirst { - ext.bundlesTargetDir.mkdirs() +// doLast { +// // replacing this text in the unpack dir causes problems for the JakartaTransformer (doesn't everything?) +// // - so we only do it in the transformed dir after the transformation happens. +// ant.replaceregexp(match:'hibernate-core', replace:'hibernate-core-jakarta', flags:'g', byline:true) { +// fileset(dir: "${project.transformedTestDir}/bundles", includes: '**/*.xml') +// } +// } + + doLast { + def transformerArgs = [ + // source dir + project.unpackedTestDir, + // target dir + project.transformedTestDir + ] + ( project.baseTransformerArgs as ArrayList ) + + println 'Transformer options (tests) :' + transformerArgs.each { + println ' [ ' + it + ' ]' + } + + javaexec { + classpath configurations.jakartaeeTransformJars + main = 'org.eclipse.transformer.jakarta.JakartaTransformer' + args = transformerArgs + } } } -processTestResources.dependsOn copyBundleResources +/** + * Allow the transformation task to process these bundles and then move them + */ +task stagePackagingTestBundles(type:Copy) { + dependsOn tasks.transformTests + mustRunAfter tasks.transformTests + + from project.file( project.transformedTestDir ) + into project.file( "${buildDir}" ) +} + +task testJar(type: Jar) { + description 'Jars the transformed tests' + + dependsOn tasks.transformTests + dependsOn tasks.stagePackagingTestBundles + mustRunAfter tasks.transformTests + mustRunAfter tasks.stagePackagingTestBundles + + from project.transformedTestDir + + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + archiveClassifier.set( 'test' ) +} artifacts { - tests new File(project.buildDir, "libs/hibernate-core-jakarta-${project.version}-test.jar") + tests tasks.testJar } test { - fileTree(project.buildDir).matching { include 'libs/*-test.jar' }.each { - def outputDir = file("${buildDir}/unpacked/" + it.name) - testClassesDirs += files(outputDir) - classpath += files(outputDir) - } + dependsOn tasks.transformJar + dependsOn tasks.transformTests + dependsOn tasks.stagePackagingTestBundles + + mustRunAfter tasks.transformJar + mustRunAfter tasks.transformTests + mustRunAfter tasks.stagePackagingTestBundles + + classpath += files( + "${buildDir}/libs/${project.transformedJarName}", + "${buildDir}/${project.transformedTestDirRelative}" + ) + testClassesDirs += files( project.layout.buildDirectory.dir( project.transformedTestDirRelative ) ) + systemProperty 'file.encoding', 'utf-8' if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) { @@ -177,4 +284,6 @@ test { jvmArgs( ['--add-opens', 'java.base/java.security=ALL-UNNAMED'] ) jvmArgs( ['--add-opens', 'java.base/java.lang=ALL-UNNAMED'] ) } + + maxHeapSize = '3G' } \ No newline at end of file diff --git a/hibernate-core/hibernate-core.gradle b/hibernate-core/hibernate-core.gradle index f2a1c3c0f8..10db463bf1 100644 --- a/hibernate-core/hibernate-core.gradle +++ b/hibernate-core/hibernate-core.gradle @@ -25,7 +25,7 @@ sourceSets { // resources inherently exclude sources test { resources { - setSrcDirs( ['src/test/java','src/test/resources','src/test/bundles'] ) + srcDir 'src/test/java' } } } @@ -196,18 +196,13 @@ tasks.compile.dependsOn generateGrammarSource task copyBundleResources (type: Copy) { ext { - bundlesTargetDir = file( "${buildDir}/bundles" ) bundleTokens = dbBundle[db] ext.bundleTokens['buildDirName'] = buildDir.absolutePath } - from file('src/test/bundles/templates') - into ext.bundlesTargetDir + from 'src/test/bundles/templates' + into "${buildDir}/bundles" filter( ReplaceTokens, tokens: ext.bundleTokens) - - doFirst { - ext.bundlesTargetDir.mkdirs() - } } processTestResources.dependsOn copyBundleResources @@ -219,6 +214,9 @@ task testJar(type: Jar, dependsOn: testClasses) { duplicatesStrategy = DuplicatesStrategy.EXCLUDE archiveClassifier.set( 'test' ) from sourceSets.test.output + from( "${buildDir}/bundles" ) { + into 'bundles' + } } artifacts { @@ -239,6 +237,7 @@ test { beforeTest { descriptor -> //println "Starting test: " + descriptor } + // Allow to exclude specific tests if (project.hasProperty('excludeTests')) { filter { From e4b56b927169b318231770af1b0854b02a6b286c Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Oct 2021 13:52:33 -0500 Subject: [PATCH 4/7] HHH-14857 - Deprecations in preparation for 6 --- .../main/java/org/hibernate/EntityMode.java | 26 ++++++++++++++++++- .../SessionFactoryOptionsBuilder.java | 12 +++++---- .../hbm/internal/EntityModeConverter.java | 21 ++++++++++++--- .../hbm/AbstractEntitySourceImpl.java | 12 +++++++++ .../org/hibernate/cfg/AvailableSettings.java | 3 +++ .../internal/log/DeprecationLogger.java | 6 +++++ 6 files changed, 71 insertions(+), 9 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/EntityMode.java b/hibernate-core/src/main/java/org/hibernate/EntityMode.java index 1f07ca88d4..522a333e34 100644 --- a/hibernate-core/src/main/java/org/hibernate/EntityMode.java +++ b/hibernate-core/src/main/java/org/hibernate/EntityMode.java @@ -8,11 +8,16 @@ package org.hibernate; import java.util.Locale; +import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; + /** * Defines the representation modes available for entities. * - * @author Steve Ebersole + * @deprecated To be removed in 6.0 in favor of `ManagedTypeRepresentationStrategy` + * and `RepresentationMode` */ +@Deprecated public enum EntityMode { /** * The {@code pojo} entity mode describes an entity model made up of entity classes (loosely) following @@ -58,4 +63,23 @@ public enum EntityMode { return valueOf( entityMode.toUpperCase( Locale.ENGLISH ) ); } + public static EntityMode fromSetting(Object setting) { + if ( setting != null ) { + DEPRECATION_LOGGER.deprecatedSetting( DEFAULT_ENTITY_MODE ); + } + + if ( setting == null || setting == POJO ) { + return POJO; + } + + if ( setting instanceof EntityMode ) { + return ( (EntityMode) setting ); + } + + if ( setting instanceof String ) { + return parse( (String) setting ); + } + + return POJO; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index ac6163fdfa..d0b4376af5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -130,6 +130,7 @@ import static org.hibernate.cfg.AvailableSettings.WRAP_RESULT_SETS; import static org.hibernate.cfg.AvailableSettings.DISCARD_PC_ON_CLOSE; import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN; import static org.hibernate.internal.CoreLogging.messageLogger; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; /** * In-flight state of {@link org.hibernate.boot.spi.SessionFactoryOptions} @@ -330,10 +331,11 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.entityNotFoundDelegate = StandardEntityNotFoundDelegate.INSTANCE; this.identifierRollbackEnabled = cfgService.getSetting( USE_IDENTIFIER_ROLLBACK, BOOLEAN, false ); - this.defaultEntityMode = EntityMode.parse( (String) configurationSettings.get( DEFAULT_ENTITY_MODE ) ); this.checkNullability = cfgService.getSetting( CHECK_NULLABILITY, BOOLEAN, true ); this.initializeLazyStateOutsideTransactions = cfgService.getSetting( ENABLE_LAZY_LOAD_NO_TRANS, BOOLEAN, false ); + this.defaultEntityMode = EntityMode.fromSetting( configurationSettings.get( DEFAULT_ENTITY_MODE ) ); + this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configurationSettings ); this.currentTenantIdentifierResolver = strategySelector.resolveStrategy( CurrentTenantIdentifierResolver.class, @@ -475,7 +477,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { null ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.DISCARD_PC_ON_CLOSE, DISCARD_PC_ON_CLOSE ); @@ -562,7 +564,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { () -> { final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.INTERCEPTOR ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.INTERCEPTOR, INTERCEPTOR ); @@ -583,7 +585,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { () -> { final Object oldSetting = configurationSettings.get( org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR ); if ( oldSetting != null ) { - DeprecationLogger.DEPRECATION_LOGGER.deprecatedSetting( + DEPRECATION_LOGGER.deprecatedSetting( org.hibernate.jpa.AvailableSettings.SESSION_INTERCEPTOR, SESSION_SCOPED_INTERCEPTOR ); @@ -659,7 +661,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { ConnectionReleaseMode specifiedReleaseMode, Map configurationSettings, TransactionCoordinatorBuilder transactionCoordinatorBuilder) { - DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings(); + DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings(); final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null ? ConnectionAcquisitionMode.AS_NEEDED diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java index d9548064fa..6c5aa1ad1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/hbm/internal/EntityModeConverter.java @@ -7,16 +7,31 @@ package org.hibernate.boot.jaxb.hbm.internal; import org.hibernate.EntityMode; +import org.hibernate.internal.log.DeprecationLogger; +import org.hibernate.internal.util.StringHelper; /** - * @author Steve Ebersole + * @deprecated for removal in 6.0 */ +@Deprecated public class EntityModeConverter { public static EntityMode fromXml(String name) { - return EntityMode.parse( name ); + final EntityMode entityMode = EntityMode.parse( name ); + if ( StringHelper.isNotEmpty( name ) ) { + DeprecationLogger.DEPRECATION_LOGGER.info( + "XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping" + ); + } + return entityMode; } public static String toXml(EntityMode entityMode) { - return ( null == entityMode ) ? null : entityMode.getExternalName(); + if ( entityMode == null ) { + return null; + } + DeprecationLogger.DEPRECATION_LOGGER.info( + "XML mapping specified an entity-mode - `%s`. Starting in 6.0 this is simply inferred from the entity/composite mapping" + ); + return entityMode.getExternalName(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java index cfb2826243..230856c212 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/AbstractEntitySourceImpl.java @@ -324,10 +324,22 @@ public abstract class AbstractEntitySourceImpl return jaxbEntityMapping.isSelectBeforeUpdate(); } + /** + * @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred + * from the entity-type mapping + */ + @Deprecated protected EntityMode determineEntityMode() { return StringHelper.isNotEmpty( entityNamingSource.getClassName() ) ? EntityMode.POJO : EntityMode.MAP; } + /** + * @deprecated to be removed in 6.0. Starting in 6.0 the mode is inferred + * from the entity-type mapping + * + * See `ManagedTypeRepresentationStrategy` and `RepresentationMode` in 6.0 + */ + @Deprecated @Override public Map getTuplizerClassMap() { return tuplizerClassMap; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index f4da85d681..59d79cb715 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -1409,7 +1409,10 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings { /** * The EntityMode in which set the Session opened from the SessionFactory. + * + * @deprecated An entity-type has one "mode" relative to any SessionFactory. */ + @Deprecated String DEFAULT_ENTITY_MODE = "hibernate.default_entity_mode"; /** diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java index 9ecfe081bf..9f709d59a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/DeprecationLogger.java @@ -297,4 +297,10 @@ public interface DeprecationLogger extends BasicLogger { ) void deprecatedJmxBeanRegistration(String name); + @LogMessage(level = WARN) + @Message( + id = 90000031, + value = "Encountered deprecated setting [%s] which is planned for removal" + ) + void deprecatedSetting(String setting); } From 85cd748de58dd090b04212ad0770f479187a29f5 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Oct 2021 14:15:57 -0500 Subject: [PATCH 5/7] improve hibernate-core-jakarta build --- hibernate-core-jakarta/hibernate-core-jakarta.gradle | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hibernate-core-jakarta/hibernate-core-jakarta.gradle b/hibernate-core-jakarta/hibernate-core-jakarta.gradle index f2b1cf528e..ce20340fef 100644 --- a/hibernate-core-jakarta/hibernate-core-jakarta.gradle +++ b/hibernate-core-jakarta/hibernate-core-jakarta.gradle @@ -118,7 +118,7 @@ task transformJar { mustRunAfter project(':hibernate-core').tasks.jar inputs.file project(':hibernate-core').tasks.jar.archiveFile - outputs.file "${buildDir}/libs/${transformedJarName}" + outputs.file tasks.jar.archiveFile.get().asFile doLast { def transformerArgs = [ @@ -141,6 +141,15 @@ task transformJar { } } +configurations { + [apiElements, runtimeElements].each { + it.outgoing.artifacts.removeIf { + it.buildDependencies.getDependencies(null).contains(jar) + } + it.outgoing.artifact(tasks.jar.archiveFile.get().asFile) + } +} + task unpackTestJar(type: Copy) { description 'Unpacks the hibernate-core test jar into a directory so we can transform it and replace token(s) in the test resources' From 1fdd0a6df12dbc9ec18e79a012390e910fd73698 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Oct 2021 14:34:26 -0500 Subject: [PATCH 6/7] improve hibernate-core-jakarta build --- .../hibernate-core-jakarta.gradle | 89 +++++++++++++------ 1 file changed, 62 insertions(+), 27 deletions(-) diff --git a/hibernate-core-jakarta/hibernate-core-jakarta.gradle b/hibernate-core-jakarta/hibernate-core-jakarta.gradle index ce20340fef..b83db47504 100644 --- a/hibernate-core-jakarta/hibernate-core-jakarta.gradle +++ b/hibernate-core-jakarta/hibernate-core-jakarta.gradle @@ -1,3 +1,5 @@ +import javax.inject.Inject + /* * Hibernate, Relational Persistence for Idiomatic Java * @@ -13,7 +15,7 @@ configurations { tests { description = 'Configuration for the produced test jar' } - jakartaeeTransformJars + jakartaeeTransformTool } dependencies { @@ -37,7 +39,7 @@ dependencies { compile( libraries.jakarta_jaxb_api ) compile( libraries.jakarta_jaxb_runtime ) - jakartaeeTransformJars 'biz.aQute.bnd:biz.aQute.bnd.transform:5.1.1', + jakartaeeTransformTool 'biz.aQute.bnd:biz.aQute.bnd.transform:5.1.1', 'commons-cli:commons-cli:1.4', 'org.slf4j:slf4j-simple:1.7.30', 'org.slf4j:slf4j-api:1.7.26', @@ -111,34 +113,14 @@ ext { ] } -task transformJar { +task transformJar(type: JakartaJarTransformation) { description 'Transforms the hibernate-core jar using the JakartaTransformer tool' dependsOn project(':hibernate-core').tasks.jar mustRunAfter project(':hibernate-core').tasks.jar - inputs.file project(':hibernate-core').tasks.jar.archiveFile - outputs.file tasks.jar.archiveFile.get().asFile - - doLast { - def transformerArgs = [ - // source jar - project(':hibernate-core').tasks.jar.archiveFile.get(), - // target jar - file( "${buildDir}/libs/${transformedJarName}" ) - ] + ( project.baseTransformerArgs as ArrayList ) - - println 'Transformer options (main) :' - transformerArgs.each { - println ' [ ' + it + ' ]' - } - - javaexec { - classpath configurations.jakartaeeTransformJars - main = 'org.eclipse.transformer.jakarta.JakartaTransformer' - args = transformerArgs - } - } + sourceJar project(':hibernate-core').tasks.jar.archiveFile + targetJar tasks.jar.archiveFile.get().asFile } configurations { @@ -146,7 +128,9 @@ configurations { it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) } - it.outgoing.artifact(tasks.jar.archiveFile.get().asFile) + it.outgoing.artifact(tasks.transformJar.targetJar) { + builtBy tasks.transformJar + } } } @@ -233,7 +217,7 @@ task transformTests { } javaexec { - classpath configurations.jakartaeeTransformJars + classpath configurations.jakartaeeTransformTool main = 'org.eclipse.transformer.jakarta.JakartaTransformer' args = transformerArgs } @@ -295,4 +279,55 @@ test { } maxHeapSize = '3G' +} + + +@CacheableTask +abstract class JakartaJarTransformation extends DefaultTask { + private final RegularFileProperty sourceJar; + private final RegularFileProperty targetJar; + + @Inject + JakartaJarTransformation(ObjectFactory objectFactory) { + sourceJar = objectFactory.fileProperty(); + targetJar = objectFactory.fileProperty(); + } + + @InputFile + @PathSensitive( PathSensitivity.RELATIVE ) + RegularFileProperty getSourceJar() { + return sourceJar; + } + + void sourceJar(Object fileReference) { + sourceJar.set( project.file( fileReference ) ) + } + + @OutputFile + RegularFileProperty getTargetJar() { + return targetJar; + } + + void targetJar(Object fileReference) { + targetJar.set( project.file( fileReference ) ) + } + + @TaskAction + void transform() { + project.javaexec( new Action() { + @Override + void execute(JavaExecSpec javaExecSpec) { + javaExecSpec.classpath( getProject().getConfigurations().getByName( "jakartaeeTransformTool" ) ); + javaExecSpec.setMain( "org.eclipse.transformer.jakarta.JakartaTransformer" ); + javaExecSpec.args( + sourceJar.get().getAsFile().getAbsolutePath(), + targetJar.get().getAsFile().getAbsolutePath(), + "-q", + "-tr", getProject().getRootProject().file( "rules/jakarta-renames.properties" ).getAbsolutePath(), + "-tv", getProject().getRootProject().file( "rules/jakarta-versions.properties" ).getAbsolutePath(), + "-td", getProject().getRootProject().file( "rules/jakarta-direct.properties" ).getAbsolutePath() + ); + } + }); + } } \ No newline at end of file From 91e29358be0a73d77ac00de45ddf56dd989fefd2 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 21 Oct 2021 16:13:55 -0500 Subject: [PATCH 7/7] HHH-14857 - Deprecations in preparation for 6 --- .../src/main/java/org/hibernate/tuple/Tuplizer.java | 4 ++++ .../java/org/hibernate/tuple/component/ComponentTuplizer.java | 4 ++++ .../main/java/org/hibernate/tuple/entity/EntityTuplizer.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/Tuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/Tuplizer.java index 9c0120b185..16ec664d32 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/Tuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/Tuplizer.java @@ -31,8 +31,12 @@ import org.hibernate.property.access.spi.Getter; * @see org.hibernate.tuple.entity.EntityTuplizer * @see org.hibernate.tuple.component.ComponentTuplizer * + * @deprecated for removal in 6.0. See instead `ManagedTypeRepresentationStrategy` + * and `RepresentationMode` in 6.0 + * * @author Steve Ebersole */ +@Deprecated public interface Tuplizer { /** * Extract the current values contained on the given entity. diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java index 916e02b6d5..75eaa2572e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/ComponentTuplizer.java @@ -20,7 +20,11 @@ import org.hibernate.tuple.Tuplizer; * * @author Gavin King * @author Steve Ebersole + * + * @deprecated for removal in 6.0. See instead `ManagedTypeRepresentationStrategy` + * and `RepresentationMode` in 6.0 */ +@Deprecated public interface ComponentTuplizer extends Tuplizer, Serializable { /** * Retrieve the current value of the parent property. diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java index 68b8b9d22f..2f7e932b4e 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityTuplizer.java @@ -28,7 +28,11 @@ import org.hibernate.tuple.Tuplizer; * * @author Gavin King * @author Steve Ebersole + * + * @deprecated for removal in 6.0. See instead `ManagedTypeRepresentationStrategy` + * and `RepresentationMode` in 6.0 */ +@Deprecated public interface EntityTuplizer extends Tuplizer { /** * Return the entity-mode handled by this tuplizer instance.