Merge branch 'master' into wip/6.0

This commit is contained in:
Andrea Boriero 2020-11-17 12:40:43 +01:00
commit 1927d1aa33
30 changed files with 729 additions and 97 deletions

View File

@ -5,10 +5,10 @@ jobs:
include: include:
- stage: Oracle JDK 8 - stage: Oracle JDK 8
jdk: oraclejdk8 jdk: oraclejdk8
- stage: AdoptOpenJDK 11.0.3 - stage: AdoptOpenJDK 11.0.9
install: install:
- curl -L -o install-jdk.sh https://github.com/sormuras/bach/raw/master/install-jdk.sh - curl -L -o install-jdk.sh https://github.com/sormuras/bach/raw/master/install-jdk.sh
- source ./install-jdk.sh --target ./openjdk11 --url https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.3%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.3_7.tar.gz - source ./install-jdk.sh --target ./openjdk11 --url https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.9%2B11.1/OpenJDK11U-jdk_x64_linux_hotspot_11.0.9_11.tar.gz
before_script: before_script:
- java -version - java -version

View File

@ -66,11 +66,14 @@ task release {
"the fact that subprojects will appropriately define a release task " + "the fact that subprojects will appropriately define a release task " +
"themselves if they have any release-related activities to perform" "themselves if they have any release-related activities to perform"
doFirst {
def javaVersionsInUse = [gradle.ext.javaVersions.main.compiler, gradle.ext.javaVersions.main.release,
gradle.ext.javaVersions.test.compiler, gradle.ext.javaVersions.test.release,
gradle.ext.javaVersions.test.launcher].toSet()
// Force to release with JDK 8. It used to not work on JDK11 because of the hibernate-orm-modules module, // Force to release with JDK 8. It used to not work on JDK11 because of the hibernate-orm-modules module,
// but this limitation might be resolved now that this module has been deleted? // but this limitation might be resolved now that this module has been deleted?
doFirst { if ( javaVersionsInUse != [JavaLanguageVersion.of( 8 )].toSet() ) {
if ( !JavaVersion.current().isJava8() || !gradle.ext.testedJavaVersionAsEnum.isJava8() ) { throw new IllegalStateException( "Please use JDK 8 to perform the release. Currently using: ${javaVersionsInUse}" )
throw new IllegalStateException( "Please use JDK 8 to perform the release." )
} }
} }
} }
@ -112,8 +115,8 @@ buildScanRecipes {
idea { idea {
// project { // project {
// jdkName = baselineJavaVersion // jdkName = gradle.ext.baselineJavaVersion
// languageLevel = baselineJavaVersion // languageLevel = gradle.ext.baselineJavaVersion
// //
// vcs = 'Git' // vcs = 'Git'
// //

View File

@ -133,17 +133,29 @@ task aggregateJavadocs(type: Javadoc) {
'https://javaee.github.io/javaee-spec/javadocs/' 'https://javaee.github.io/javaee-spec/javadocs/'
] ]
if ( JavaVersion.current().isJava11Compatible() ) { if ( gradle.ext.javaVersions.main.compiler.asInt() >= 11 ) {
//The need to set `--source 1.8` applies to all JVMs after 11, and also to 11 //The need to set `--source 1.8` applies to all JVMs after 11, and also to 11
// but after excluding the first two builds; see also specific comments on // but after excluding the first two builds; see also specific comments on
// https://bugs.openjdk.java.net/browse/JDK-8212233?focusedCommentId=14245762 // https://bugs.openjdk.java.net/browse/JDK-8212233?focusedCommentId=14245762
// For now, let's be compatible with JDK 11.0.3+. We can improve on it if people // For now, let's be compatible with JDK 11.0.3+. We can improve on it if people
// complain they cannot build with JDK 11.0.0, 11.0.1 and 11.0.2. // complain they cannot build with JDK 11.0.0, 11.0.1 and 11.0.2.
System.out.println("Forcing Javadoc in Java 8 compatible mode"); logger.lifecycle "Forcing Javadoc in Java 8 compatible mode"
options.source = project.baselineJavaVersion options.source = gradle.ext.baselineJavaVersion
} }
options.addStringOption( 'Xdoclint:none', '-quiet' ) options.addStringOption( 'Xdoclint:none', '-quiet' )
if ( gradle.ext.javaToolchainEnabled ) {
options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().
split( ' ' ).toList().findAll( { !it.isEmpty() } ) )
}
}
if ( gradle.ext.javaToolchainEnabled ) {
// Display version of Java tools
doFirst {
logger.lifecycle "Aggregating javadoc with '${javadocTool.get().metadata.installationPath}'"
}
} }
// process each project, building up: // process each project, building up:

View File

@ -1,2 +1,16 @@
# Keep system properties in sync with test system properties (java-module.gradle)! # Keep all these properties in sync unless you know what you are doing!
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
toolchain.compiler.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
toolchain.javadoc.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
toolchain.launcher.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8
# JDK auto-detection is not quite ready yet in Gradle 6.7.
# On Fedora in particular, if you have the package java-1.8.0-openjdk-headless-1.8.0.265.b01-1.fc32.x86_64 installed,
# Gradle will look for the Java binaries in /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.265.b01-1.fc32.x86_64/bin/java
# but it won't find it and will fail.
# It's just a JRE, so it's perfectly normal that the JDK is not present;
# the JRE is under /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.265.b01-1.fc32.x86_64/jre
org.gradle.java.installations.auto-detect=false
# We can't rely on Gradle's auto-download of JDKs as it doesn't support EA releases.
# See https://github.com/gradle/gradle/blob/fc7ea24f3c525d8d12a4346eb0f15976a6be9414/subprojects/platform-jvm/src/main/java/org/gradle/jvm/toolchain/install/internal/AdoptOpenJdkRemoteBinary.java#L114
org.gradle.java.installations.auto-download=false

View File

@ -16,7 +16,6 @@ ext {
if ( project.hasProperty( 'releaseVersion' ) ) { if ( project.hasProperty( 'releaseVersion' ) ) {
ormVersion = new HibernateVersion( project.releaseVersion, project ) ormVersion = new HibernateVersion( project.releaseVersion, project )
} }
baselineJavaVersion = '1.8'
jpaVersion = new JpaVersion('2.2') jpaVersion = new JpaVersion('2.2')
} }

View File

@ -134,17 +134,72 @@ dependencies {
tasks.withType( JavaCompile ) { tasks.withType( JavaCompile ) {
options.encoding = 'UTF-8' options.encoding = 'UTF-8'
sourceCompatibility = project.baselineJavaVersion
targetCompatibility = project.baselineJavaVersion
} }
if ( project.baselineJavaVersion != gradle.ext.testedJavaVersion ) { if ( !gradle.ext.javaToolchainEnabled ) {
logger.info( "Forcing the target bytecode version for test classes to '$gradle.ext.testedJavaVersion'" ) tasks.compileJava.configure {
sourceCompatibility = JavaVersion.toVersion( gradle.ext.javaVersions.main.release )
targetCompatibility = JavaVersion.toVersion( gradle.ext.javaVersions.main.release )
}
tasks.compileTestJava.configure {
sourceCompatibility = JavaVersion.toVersion( gradle.ext.javaVersions.test.release )
targetCompatibility = JavaVersion.toVersion( gradle.ext.javaVersions.test.release )
}
}
else {
// Configure generated bytecode
// "sourceCompatibility" is not supported with toolchains. We have to work around that limitation.
tasks.compileJava.configure {
if ( gradle.ext.javaVersions.main.compiler.asInt() < 9 ) {
options.compilerArgs << '-source'
options.compilerArgs << gradle.ext.javaVersions.main.release.toString()
options.compilerArgs << '-target'
options.compilerArgs << gradle.ext.javaVersions.main.release.toString()
} else {
options.release = gradle.ext.javaVersions.main.release.asInt()
}
}
tasks.compileTestJava.configure {
if ( gradle.ext.javaVersions.test.compiler.asInt() < 9 ) {
options.compilerArgs << '-source'
options.compilerArgs << gradle.ext.javaVersions.test.release.toString()
options.compilerArgs << '-target'
options.compilerArgs << gradle.ext.javaVersions.test.release.toString()
} else {
options.release = gradle.ext.javaVersions.test.release.asInt()
}
}
// Configure version of Java tools
java {
toolchain {
languageVersion = gradle.ext.javaVersions.main.compiler
}
}
tasks.compileTestJava { tasks.compileTestJava {
// For *tests only*, generate bytecode matching the Java version currently in use. javaCompiler = javaToolchains.compilerFor {
// This allows testing bytecode enhancement on the latest Java versions (13, 14, ...). languageVersion = gradle.ext.javaVersions.test.compiler
targetCompatibility = gradle.ext.testedJavaVersion }
}
// Configure JVM Options
tasks.withType( JavaCompile ).configureEach {
options.forkOptions.jvmArgs.addAll( getProperty( 'toolchain.compiler.jvmargs' ).toString().split( ' ' ) )
}
tasks.withType( Javadoc ).configureEach {
options.setJFlags( getProperty( 'toolchain.javadoc.jvmargs' ).toString().split( ' ' ).toList().findAll( { !it.isEmpty() } ) )
}
// Display version of Java tools
tasks.withType( JavaCompile ).configureEach {
doFirst {
logger.lifecycle "Compiling with '${javaCompiler.get().metadata.installationPath}'"
}
}
tasks.withType( Javadoc ).configureEach {
doFirst {
logger.lifecycle "Generating javadoc with '${javadocTool.get().metadata.installationPath}'"
}
} }
} }
@ -188,10 +243,27 @@ if ( ext.toolsJar.exists() ) {
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Testing // Testing
if ( gradle.ext.javaToolchainEnabled ) {
tasks.test {
// Configure version of Java tools
javaLauncher = javaToolchains.launcherFor {
languageVersion = gradle.ext.javaVersions.test.launcher
}
// Configure JVM Options
jvmArgs.addAll( getProperty( 'toolchain.launcher.jvmargs' ).toString().split( ' ' ) )
// Display version of Java tools
doFirst {
logger.lifecycle "Testing with '${javaLauncher.get().metadata.installationPath}'"
}
}
}
tasks.withType( Test.class ).each { test -> tasks.withType( Test.class ).each { test ->
test.useJUnitPlatform() test.useJUnitPlatform()
if ( JavaVersion.current().isJava9Compatible() ) { if ( gradle.ext.javaVersions.test.launcher.asInt() >= 9 ) {
// Byteman needs this property to be set, https://developer.jboss.org/thread/274997 // Byteman needs this property to be set, https://developer.jboss.org/thread/274997
test.jvmArgs += ["-Djdk.attach.allowAttachSelf=true"] test.jvmArgs += ["-Djdk.attach.allowAttachSelf=true"]
} }
@ -254,8 +326,8 @@ test {
// Enable the experimental features of ByteBuddy with JDK 15+ // Enable the experimental features of ByteBuddy with JDK 15+
test { test {
if ( Integer.valueOf( gradle.ext.testedJavaVersionAsEnum.getMajorVersion() ) >= 15 ) { if ( gradle.ext.javaVersions.test.release.asInt() >= 15 ) {
logger.warn( "The version of java that will be tested is not supported by Bytebuddy by default. " + logger.warn( "The version of Java bytecode that will be tested is not supported by Bytebuddy by default. " +
" Setting 'net.bytebuddy.experimental=true'." ) " Setting 'net.bytebuddy.experimental=true'." )
systemProperty 'net.bytebuddy.experimental', true systemProperty 'net.bytebuddy.experimental', true
} }
@ -385,7 +457,7 @@ task forbiddenApisUnsafe(type: CheckForbiddenApis, dependsOn: compileJava) {
classesDirs = project.sourceSets.main.output.classesDirs classesDirs = project.sourceSets.main.output.classesDirs
classpath = project.sourceSets.main.compileClasspath + project.sourceSets.main.runtimeClasspath classpath = project.sourceSets.main.compileClasspath + project.sourceSets.main.runtimeClasspath
targetCompatibility = project.forbiddenAPITargetJDKCompatibility targetCompatibility = project.forbiddenAPITargetJDKCompatibility
bundledSignatures += "jdk-unsafe-${baselineJavaVersion}".toString() bundledSignatures += "jdk-unsafe-${gradle.ext.baselineJavaVersion}".toString()
// unfortunately we currently have many uses of default Locale implicitly (~370) which need to be fixed // unfortunately we currently have many uses of default Locale implicitly (~370) which need to be fixed
// before we can fully enabled this check // before we can fully enabled this check

View File

@ -25,7 +25,7 @@ ext {
cdiVersion = '2.0' cdiVersion = '2.0'
weldVersion = '3.0.0.Final' weldVersion = '3.0.0.Final'
javassistVersion = '3.24.0-GA' javassistVersion = '3.27.0-GA'
byteBuddyVersion = '1.10.17' byteBuddyVersion = '1.10.17'
agroalVersion = '1.9' agroalVersion = '1.9'

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

2
gradlew vendored
View File

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath

1
gradlew.bat vendored
View File

@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View File

@ -139,6 +139,8 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
@Override @Override
public void stop() { public void stop() {
if ( agroalDataSource != null ) {
agroalDataSource.close(); agroalDataSource.close();
} }
} }
}

View File

@ -91,7 +91,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
} }
} }
this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] ); this.affectedTableSpaces = spacesList.toArray( new String[ 0 ] );
} }
/** /**
@ -106,7 +106,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
* @param session The session to which this request is tied. * @param session The session to which this request is tied.
* @param tableSpaces The table spaces. * @param tableSpaces The table spaces.
*/ */
@SuppressWarnings({ "unchecked" }) @SuppressWarnings( { "unchecked", "rawtypes" } )
public BulkOperationCleanupAction(SharedSessionContractImplementor session, Set tableSpaces) { public BulkOperationCleanupAction(SharedSessionContractImplementor session, Set tableSpaces) {
final LinkedHashSet<String> spacesList = new LinkedHashSet<>( tableSpaces ); final LinkedHashSet<String> spacesList = new LinkedHashSet<>( tableSpaces );
@ -138,23 +138,26 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
} }
} }
this.affectedTableSpaces = spacesList.toArray( new String[ spacesList.size() ] ); this.affectedTableSpaces = spacesList.toArray( new String[ 0 ] );
} }
/** /**
* Check to determine whether the table spaces reported by an entity * Check whether we should consider an entity as affected by the query. This
* persister match against the defined affected table spaces. * defines inclusion of the entity in the clean-up.
* *
* @param affectedTableSpaces The table spaces reported to be affected by * @param affectedTableSpaces The table spaces reported to be affected by
* the query. * the query.
* @param checkTableSpaces The table spaces (from the entity persister) * @param checkTableSpaces The table spaces (from the entity persister)
* to check against the affected table spaces. * to check against the affected table spaces.
* *
* @return True if there are affected table spaces and any of the incoming * @return Whether the entity should be considered affected
* check table spaces occur in that set. *
* @implNote An entity is considered to be affected if either (1) the affected table
* spaces are not known or (2) any of the incoming check table spaces occur
* in that set.
*/ */
private boolean affectedEntity(Set affectedTableSpaces, Serializable[] checkTableSpaces) { private boolean affectedEntity(Set<?> affectedTableSpaces, Serializable[] checkTableSpaces) {
if ( affectedTableSpaces == null || affectedTableSpaces.isEmpty() ) { if ( affectedTableSpaces == null || affectedTableSpaces.isEmpty() ) {
return true; return true;
} }
@ -179,9 +182,7 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
@Override @Override
public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() { public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() {
return new AfterTransactionCompletionProcess() { return (success, session) -> {
@Override
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
for ( EntityCleanup cleanup : entityCleanups ) { for ( EntityCleanup cleanup : entityCleanups ) {
cleanup.release(); cleanup.release();
} }
@ -196,7 +197,6 @@ public class BulkOperationCleanupAction implements Executable, Serializable {
cleanup.release(); cleanup.release();
} }
collectionCleanups.clear(); collectionCleanups.clear();
}
}; };
} }

View File

@ -210,11 +210,17 @@ public class DriverManagerConnectionProviderImpl
@Override @Override
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
if ( state == null ) {
throw new IllegalStateException( "Cannot get a connection as the driver manager is not properly initialized" );
}
return state.getConnection(); return state.getConnection();
} }
@Override @Override
public void closeConnection(Connection conn) throws SQLException { public void closeConnection(Connection conn) throws SQLException {
if ( state == null ) {
throw new IllegalStateException( "Cannot close a connection as the driver manager is not properly initialized" );
}
state.closeConnection( conn ); state.closeConnection( conn );
} }
@ -246,13 +252,17 @@ public class DriverManagerConnectionProviderImpl
@Override @Override
public void stop() { public void stop() {
if ( state != null ) {
state.stop(); state.stop();
} }
}
//CHECKSTYLE:START_ALLOW_FINALIZER //CHECKSTYLE:START_ALLOW_FINALIZER
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
if ( state != null ) {
state.stop(); state.stop();
}
super.finalize(); super.finalize();
} }
//CHECKSTYLE:END_ALLOW_FINALIZER //CHECKSTYLE:END_ALLOW_FINALIZER

View File

@ -11,8 +11,10 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import org.hibernate.AssertionFailure;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.engine.internal.ForeignKeys;
import org.hibernate.engine.jdbc.Size; import org.hibernate.engine.jdbc.Size;
import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.Mapping; import org.hibernate.engine.spi.Mapping;
@ -115,12 +117,19 @@ public class OneToOneType extends EntityType {
@Override @Override
public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) { public boolean isDirty(Object old, Object current, SharedSessionContractImplementor session) {
if ( isSame( old, current ) ) {
return false; return false;
} }
Object oldid = getIdentifier( old, session );
Object newid = getIdentifier( current, session );
return getIdentifierType( session ).isDirty( oldid, newid, session );
}
@Override @Override
public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) { public boolean isDirty(Object old, Object current, boolean[] checkable, SharedSessionContractImplementor session) {
return false; return isDirty(old, current, session);
} }
@Override @Override
@ -154,25 +163,36 @@ public class OneToOneType extends EntityType {
@Override @Override
public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException { public Serializable disassemble(Object value, SharedSessionContractImplementor session, Object owner) throws HibernateException {
if (value == null) {
return null; return null;
} }
Object id = ForeignKeys.getEntityIdentifierIfNotUnsaved( getAssociatedEntityName(), value, session );
if ( id == null ) {
throw new AssertionFailure(
"cannot cache a reference to an object with a null id: " +
getAssociatedEntityName()
);
}
return getIdentifierType( session ).disassemble( id, session, owner );
}
@Override @Override
public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException { public Object assemble(Serializable oid, SharedSessionContractImplementor session, Object owner) throws HibernateException {
//this should be a call to resolve(), not resolveIdentifier(), //the owner of the association is not the owner of the id
//'cos it might be a property-ref, and we did not cache the Serializable id = ( Serializable ) getIdentifierType( session ).assemble( oid, session, null );
//referenced value
return resolve( session.getContextEntityIdentifier(owner), session, owner ); if ( id == null ) {
return null;
}
return resolveIdentifier( id, session );
} }
/**
* We don't need to dirty check one-to-one because of how
* assemble/disassemble is implemented and because a one-to-one
* association is never dirty
*/
@Override @Override
public boolean isAlwaysDirtyChecked() { public boolean isAlwaysDirtyChecked() {
//TODO: this is kinda inconsistent with CollectionType return true;
return false;
} }
} }

View File

@ -50,6 +50,20 @@ public class StoredProcedureApiTests extends BaseNonConfigCoreFunctionalTestCase
); );
} }
@Test
public void parameterValueAccessByName() {
inTransaction(
session -> {
final ProcedureCall call = session.createStoredProcedureCall( "test" );
call.registerStoredProcedureParameter("a", Integer.class, ParameterMode.IN);
call.registerStoredProcedureParameter( "b", String.class, ParameterMode.OUT);
call.setParameter( "a", 1 );
call.getParameterValue( "a" );
}
);
}
@Test @Test
public void testInvalidParameterReference() { public void testInvalidParameterReference() {
inTransaction( inTransaction(

View File

@ -7,6 +7,7 @@
package org.hibernate.test.hql; package org.hibernate.test.hql;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -156,4 +157,102 @@ public class ParameterTest extends BaseCoreFunctionalTestCase {
s.getTransaction().commit(); s.getTransaction().commit();
s.close(); s.close();
} }
@Test
@TestForIssue(jiraKey = "HHH-13310")
public void testGetParameterListValue() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in :ids" );
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
Object parameterListValue = query.getParameterValue( "ids" );
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-13310")
public void testGetParameterListValueAfterParameterExpansion() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in :ids" );
query.setParameterList( "ids", Arrays.asList( 1L, 2L ) );
query.list();
Object parameterListValue = query.getParameterValue( "ids" );
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
}
);
}
@Test(expected = IllegalStateException.class)
@TestForIssue(jiraKey = "HHH-13310")
public void testGetNotBoundParameterListValue() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in :ids" );
query.getParameterValue( "ids" );
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-13310")
public void testGetPositionalParameterListValue() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in ?1" );
query.setParameter( 1, Arrays.asList( 1L, 2L ) );
Object parameterListValue = query.getParameterValue( 1 );
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
query.list();
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-13310")
public void testGetPositionalParameterValue() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id = ?1" );
query.setParameter( 1, 1L );
Object parameterListValue = query.getParameterValue( 1 );
assertThat( parameterListValue, is( 1L ) );
query.list();
}
);
}
@Test
@TestForIssue(jiraKey = "HHH-13310")
public void testGetParameterByPositionListValueAfterParameterExpansion() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in ?1" );
query.setParameterList( 1, Arrays.asList( 1L, 2L ) );
query.list();
Object parameterListValue = query.getParameterValue( 1 );
assertThat( parameterListValue, is( Arrays.asList( 1L, 2L ) ) );
}
);
}
@Test(expected = IllegalStateException.class)
@TestForIssue(jiraKey = "HHH-13310")
public void testGetPositionalNotBoundParameterListValue() {
inTransaction(
session -> {
Query query = session.createQuery( "from Animal a where a.id in ?1" );
query.getParameterValue( 1 );
}
);
}
} }

View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.onetoone.cache">
<class name="DetailsByFK">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">
<generator class="foreign">
<param name="property">person</param>
</generator>
</id>
<one-to-one name="person" class="PersonByFK" constrained="true"/>
<property name="data"/>
</class>
<class name="DetailsByRef">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<many-to-one name="person" class="PersonByRef" column="personId" unique="true"/>
<property name="data"/>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,38 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
import java.io.Serializable;
public abstract class Details implements Serializable {
private int id;
private String data;
private Person person;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public Person getPerson() {
return person;
}
protected void setPerson(Person person) {
this.person = person;
}
}

View File

@ -0,0 +1,9 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
public class DetailsByFK extends Details {}

View File

@ -0,0 +1,9 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
public class DetailsByRef extends Details {}

View File

@ -0,0 +1,120 @@
package org.hibernate.test.onetoone.cache;
import static org.junit.Assert.assertEquals;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cache.spi.CacheImplementor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
public class OneToOneCacheTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
return new String[] {
"onetoone/cache/Details.hbm.xml",
"onetoone/cache/Person.hbm.xml",
};
}
@Override
protected void configure(Configuration configuration) {
configuration.setProperty(AvailableSettings.USE_SECOND_LEVEL_CACHE, "true");
configuration.setProperty(AvailableSettings.GENERATE_STATISTICS, "true");
}
private <TPerson extends Person, TDetails extends Details> void OneToOneTest(Class<TPerson> personClass,
Class<TDetails> detailsClass) throws Exception {
// Initialize the database with data.
List<Object> ids = createPersonsAndDetails(personClass, detailsClass);
// Clear the second level cache and the statistics.
SessionFactoryImplementor sfi = sessionFactory();
CacheImplementor cache = sfi.getCache();
StatisticsImplementor statistics = sfi.getStatistics();
cache.evictEntityData(personClass);
cache.evictEntityData(detailsClass);
cache.evictQueryRegions();
statistics.clear();
// Fill the empty caches with data.
this.getPersons(personClass, ids);
// Verify that no data was retrieved from the cache.
assertEquals("Second level cache hit count", 0, statistics.getSecondLevelCacheHitCount());
statistics.clear();
this.getPersons(personClass, ids);
// Verify that all data was retrieved from the cache.
assertEquals("Second level cache miss count", 0, statistics.getSecondLevelCacheMissCount());
}
private <TPerson extends Person, TDetails extends Details> List<Object> createPersonsAndDetails(Class<TPerson> personClass,
Class<TDetails> detailsClass) throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Constructor<TPerson> ctorPerson = personClass.getConstructor();
Constructor<TDetails> ctorDetails = detailsClass.getConstructor();
List<Object> ids = new ArrayList<>();
for (int i = 0; i < 6; i++) {
Person person = ctorPerson.newInstance();
if (i % 2 == 0) {
Details details = ctorDetails.newInstance();
details.setData(String.format("%s%d", detailsClass.getName(), i));
person.setDetails(details);
}
person.setName(String.format("%s%d", personClass.getName(), i));
ids.add(s.save(person));
}
tx.commit();
s.close();
return ids;
}
private <TPerson extends Person> List<TPerson> getPersons(Class<TPerson> personClass, List<Object> ids) {
Session s = openSession();
Transaction tx = s.beginTransaction();
List<TPerson> people = new ArrayList<>();
for (Object id : ids) {
people.add(s.get(personClass, id));
}
tx.commit();
s.close();
return people;
}
@Test
public void OneToOneCacheByForeignKey() throws Exception {
OneToOneTest(PersonByFK.class, DetailsByFK.class);
}
@Test
public void OneToOneCacheByRef() throws Exception {
OneToOneTest(PersonByRef.class, DetailsByRef.class);
}
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.test.onetoone.cache">
<class name="PersonByFK" batch-size="3">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name"/>
<one-to-one name="details" class="DetailsByFK" fetch="join" cascade="all"/>
</class>
<class name="PersonByRef" batch-size="3">
<cache usage="read-write"/>
<id name="id" unsaved-value="0">
<generator class="native"/>
</id>
<property name="name"/>
<one-to-one name="details" class="DetailsByRef" property-ref="person" fetch="join" cascade="all"/>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,43 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
import java.io.Serializable;
public abstract class Person implements Serializable {
private int id;
private String name;
private Details details;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Details getDetails() {
return details;
}
public void setDetails(Details details) {
if (details != null) {
details.setPerson(this);
}
this.details = details;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,9 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
public class PersonByFK extends Person {}

View File

@ -0,0 +1,9 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.onetoone.cache;
public class PersonByRef extends Person {}

View File

@ -24,11 +24,31 @@ apply from: rootProject.file( 'gradle/java-module.gradle' )
// so we have to use https://github.com/java9-modularity/gradle-modules-plugin // so we have to use https://github.com/java9-modularity/gradle-modules-plugin
apply plugin: "org.javamodularity.moduleplugin" apply plugin: "org.javamodularity.moduleplugin"
// Override -source and -target to the version being tested (11+, since this module is enabled) // In this module, the "main" code is actually just test code that happens
ext.baselineJavaVersion = gradle.ext.testedJavaVersion // to be built independently so as to generate a Java module.
tasks.withType( JavaCompile ) { // So, let's override settings for compilation of the main code, just for this particular case.
sourceCompatibility = project.baselineJavaVersion def testJavaVersions = gradle.ext.javaVersions.test
targetCompatibility = project.baselineJavaVersion tasks.compileJava {
if ( !gradle.ext.javaToolchainEnabled ) {
sourceCompatibility = JavaVersion.toVersion( testJavaVersions.release )
targetCompatibility = JavaVersion.toVersion( testJavaVersions.release )
}
else {
javaCompiler = javaToolchains.compilerFor {
languageVersion = testJavaVersions.compiler
}
// Remove JDK8-only options (if any) that are incompatible with options.release
for ( it = options.compilerArgs.listIterator(); it.hasNext(); ) {
if ( it.next() in ['-source', '-target'] ) {
it.remove()
it.next()
it.remove()
}
}
options.release = testJavaVersions.release.asInt()
}
} }
// Checkstyle fails for module-info // Checkstyle fails for module-info

View File

@ -35,7 +35,7 @@ ext {
* > A bit ironic since the problems we were trying to solve initially only affected JDK11.0.3, * > A bit ironic since the problems we were trying to solve initially only affected JDK11.0.3,
* > not JDK11.0.0. * > not JDK11.0.0.
*/ */
if ( JavaVersion.current().isJava11Compatible() ) { if ( gradle.ext.javaVersions.test.launcher.asInt() >= 11 ) {
logger.warn( '[WARN] Skipping all tests for hibernate-osgi due to Karaf/Pax-Exam issues with latest JDK 11' ) logger.warn( '[WARN] Skipping all tests for hibernate-osgi due to Karaf/Pax-Exam issues with latest JDK 11' )
test.enabled = false test.enabled = false
} }

View File

@ -13,35 +13,79 @@ if ( !JavaVersion.current().java8Compatible ) {
throw new GradleException( "Gradle must be run with Java 8 or later" ) throw new GradleException( "Gradle must be run with Java 8 or later" )
} }
// Consume the property 'testedJavaVersion' here and gradle.ext.baselineJavaVersion = JavaLanguageVersion.of( 8 )
// set it on gradle.ext so that we can inspect the result in build.gradle.
// We wouldn't be able to do that if we consumed
// the property in base-information.gradle and set it on project.ext.
if ( hasProperty( 'testedJavaVersion' ) ) { // Gradle does bytecode transformation on tests.
logger.warn( "[WARN] Targeting Java version '$testedJavaVersion' in tests." ) // You can't use bytecode higher than what Gradle supports, even with toolchains.
gradle.ext.testedJavaVersion = testedJavaVersion def GRADLE_MAX_SUPPORTED_BYTECODE_VERSION = 15
gradle.ext.testedJavaVersionAsEnum = JavaVersion.toVersion( testedJavaVersion )
// If either 'main.jdk.version' or 'test.jdk.version' is set, enable the toolchain and use the selected jdk.
// If only one property is set, the other defaults to the baseline Java version (8).
// Note that when toolchain is enabled, you also need to specify
// the location of the selected jdks
// (auto-download and auto-detect are disabled in gradle.properties).
//
// Example (with SDKMAN):
// ./gradlew build -Ptest.jdk.version=15 \
// -Porg.gradle.java.installations.paths=$SDKMAN_CANDIDATES_DIR/java/15.0.1-open,$SDKMAN_CANDIDATES_DIR/java/8
if ( hasProperty( 'main.jdk.version' ) || hasProperty( 'test.jdk.version' ) ) {
// Testing a particular JDK version
// Gradle doesn't support all JDK versions unless we use toolchains
gradle.ext.javaToolchainEnabled = true
gradle.ext.javaVersions = [
main: [
compiler: JavaLanguageVersion.of( hasProperty( 'main.jdk.version' )
? getProperty( 'main.jdk.version' ) : gradle.ext.baselineJavaVersion.asInt() ),
release: gradle.ext.baselineJavaVersion
],
test: [
compiler: JavaLanguageVersion.of( hasProperty( 'test.jdk.version' )
? getProperty( 'test.jdk.version' ) : gradle.ext.baselineJavaVersion.asInt() )
]
]
def testCompilerVersion = gradle.ext.javaVersions.test.compiler
if ( testCompilerVersion.asInt() > GRADLE_MAX_SUPPORTED_BYTECODE_VERSION ) {
logger.warn( "[WARN] Gradle does not support bytecode version '${testCompilerVersion}'." +
" Forcing test bytecode to version ${GRADLE_MAX_SUPPORTED_BYTECODE_VERSION}." )
gradle.ext.javaVersions.test.release = JavaLanguageVersion.of( GRADLE_MAX_SUPPORTED_BYTECODE_VERSION )
} }
else { else {
// We will simply use Gradle's JDK for compilation, tests and javadoc generation. gradle.ext.javaVersions.test.release = testCompilerVersion
def major }
if ( JavaVersion.current() == JavaVersion.VERSION_HIGHER) { gradle.ext.javaVersions.test.launcher = testCompilerVersion
logger.warn( "Gradle does not support this JDK, because it is too recent; build is likely to fail." +
" To avoid failures, you should specify an older Java version in the 'testedJavaVersion' parameter." +
" Just append the following to your gradle command:" +
" '-PtestedJavaVersion=<major version of your newer JDK, e.g. 14>'" )
// Use a hack to retrieve the major as a string.
// This only works for Java 9+ (we're at least on Java 18 here).
gradle.ext.testedJavaVersion = System.getProperty( 'java.specification.version' )
} }
else { else {
gradle.ext.testedJavaVersion = JavaVersion.current().getMajorVersion() // Not testing a particular JDK version: we will use the same JDK used to run Gradle.
// We disable toolchains for convenience, so that anyone can just run the build with their own JDK
// without any additional options and without downloading the whole JDK.
gradle.ext.javaToolchainEnabled = false
def gradleJdkVersion = JavaLanguageVersion.of( JavaVersion.current().getMajorVersion() )
if ( gradleJdkVersion.asInt() > GRADLE_MAX_SUPPORTED_BYTECODE_VERSION ) {
logger.warn( "[WARN] Gradle does not support this JDK, because it is too recent; build is likely to fail." +
" To avoid failures, you should use an older Java version when running Gradle, and rely on toolchains." +
" To that end, specify the version of Java you want to run tests with using property 'test.jdk.version'," +
" and specify the path to JDK8 *and* a JDK of the test version using property 'org.gradle.java.installations.paths'." +
" Example:" +
"./gradlew build -Ptest.jdk.version=15 -Porg.gradle.java.installations.paths=\$SDKMAN_CANDIDATES_DIR/java/15.0.1-open,\$SDKMAN_CANDIDATES_DIR/java/8" )
} }
gradle.ext.testedJavaVersionAsEnum = JavaVersion.current() gradle.ext.javaVersions = [
main: [
compiler: gradleJdkVersion,
release: gradle.ext.baselineJavaVersion
],
test: [
compiler: gradleJdkVersion,
release: JavaLanguageVersion.of(
Math.min( GRADLE_MAX_SUPPORTED_BYTECODE_VERSION, gradleJdkVersion.asInt() ) ),
launcher: gradleJdkVersion
]
]
} }
logger.lifecycle "Java versions for main code: " + gradle.ext.javaVersions.main
logger.lifecycle "Java versions for tests: " + gradle.ext.javaVersions.test
include 'hibernate-core' include 'hibernate-core'
include 'hibernate-entitymanager' include 'hibernate-entitymanager'
include 'hibernate-testing' include 'hibernate-testing'
@ -65,7 +109,12 @@ include 'hibernate-infinispan'
include 'hibernate-graalvm' include 'hibernate-graalvm'
if ( JavaVersion.current().isJava11Compatible() ) { // The plugin used to generate Java modules was compiled using JDK11.
// This means even with toolchains, Gradle needs to be run with Java 11+ in order to run Java modules ITs.
// We might be able to get rid of that limitation by relying on Gradle's built-in support for Java modules,
// but I (Yoann) tried and failed to make it work.
// See https://docs.gradle.org/current/samples/sample_java_modules_multi_project.html
if ( JavaVersion.current().isJava11Compatible() && gradle.ext.javaVersions.test.release.asInt() >= 9 ) {
include 'hibernate-integrationtest-java-modules' include 'hibernate-integrationtest-java-modules'
} }
else { else {

View File

@ -119,3 +119,18 @@ publishing {
} }
} }
tasks.withType( GroovyCompile ) {
options.encoding = 'UTF-8'
}
if ( !gradle.ext.javaToolchainEnabled ) {
tasks.withType( GroovyCompile ) {
sourceCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
targetCompatibility = JavaVersion.toVersion( gradle.ext.baselineJavaVersion )
}
}
else {
logger.warn( "[WARN] Toolchains are not yet supported for Groovy compilation." +
" Using the JDK that runs Gradle for Groovy compilation." )
}