Merge commit '5104c4b7f3b99e8a78236053ac26aa59ed82f301' into HHH-13765

This commit is contained in:
lelmarir 2020-03-31 14:26:35 +02:00
commit cf36e2bbef
11 changed files with 603 additions and 39 deletions

View File

@ -3,6 +3,38 @@ Hibernate 5 Changelog
Note: Please refer to JIRA to learn more about each issue.
Changes in 5.4.13.Final (March 26, 2020)
------------------------------------------------------------------------------------------------------------------------
https://hibernate.atlassian.net/projects/HHH/versions/31829/tab/release-report-done
** Bug
* [HHH-13322] - Sequence increment is not correctly determined
* [HHH-13619] - size() does not work properly as select expression
* [HHH-13711] - H2 dialect not accurate for drop table since version 1.4.200
* [HHH-13870] - Gradle plugin causes compile task to be always out of date
* [HHH-13875] - Optional one-to-one does not always join the associated entity table when querying
* [HHH-13876] - Fix an obvious bug in StandardStack implementation
* [HHH-13891] - ProxyFactory should not be built if any ID or property getter/setter methods are final
* [HHH-13910] - MySQL57Dialect selected by automatic dialect resolution when using MySQL 8.0 database
** New Feature
* [HHH-13799] - JPA Criteria API support for Hibernate Spatial
** Task
* [HHH-13874] - Deprecate relevant methods that are supposed to be removed in v6.0
** Improvement
* [HHH-13103] - Allow Hibernate Types to get access to the current configuration properties using constructor injection
* [HHH-13853] - Pass the merged Integration settings and Persistence Unit properties to buildBootstrapServiceRegistry
* [HHH-13855] - Remove unnecessary declaration of JtaManager in HibernatePersistenceProviderAdaptor
* [HHH-13872] - Make the Java Stream close the underlying ScrollableResultsIterator upon calling a terminal operation
* [HHH-13873] - IdTableHelper can skip opening a connection when there's no statements to execute
* [HHH-13878] - Increase the scope of some methods to make them accessible outside of Hibernate ORM
* [HHH-13879] - Slow query log should use System#nanoTime not System#currentTimeMillis
* [HHH-13897] - ResultSetProcessingContextImpl: no need to clear collections before discarding the reference to them
Changes in 5.4.12.Final (February 13, 2020)
------------------------------------------------------------------------------------------------------------------------

View File

@ -8,7 +8,7 @@
apply plugin: 'base'
ext {
ormVersion = new HibernateVersion( '5.4.13-SNAPSHOT', project )
ormVersion = new HibernateVersion( '5.4.13.Final', project )
baselineJavaVersion = '1.8'
jpaVersion = new JpaVersion('2.2')
}

View File

@ -358,6 +358,14 @@ public enum Database {
return new MySQL57Dialect();
}
}
else if ( majorVersion < 8) {
// There is no MySQL 6 or 7.
// Adding this just in case.
return new MySQL57Dialect();
}
else if ( majorVersion == 8 ) {
return new MySQL8Dialect();
}
return latestDialectInstance( this );
}

View File

@ -259,11 +259,6 @@ public class H2Dialect extends Dialect {
return false;
}
@Override
public boolean supportsIfExistsAfterTableName() {
return true;
}
@Override
public boolean supportsIfExistsBeforeConstraintName() {
return true;
@ -434,13 +429,28 @@ public class H2Dialect extends Dialect {
return false;
}
// Do not drop constraints explicitly, just do this by cascading instead.
@Override
public boolean dropConstraints() {
// We don't need to drop constraints before dropping tables, that just leads to error
// messages about missing tables when we don't have a schema in the database
return false;
}
@Override
public String getCascadeConstraintsString() {
return " CASCADE ";
}
// CASCADE has to be AFTER IF EXISTS in case it's after the tablename
@Override
public boolean supportsIfExistsAfterTableName() {
return false;
}
@Override
public boolean supportsIfExistsBeforeTableName() {
return true;
}
@Override
public IdentityColumnSupport getIdentityColumnSupport() {
return new H2IdentityColumnSupport();

View File

@ -74,7 +74,7 @@ public class CollectionSizeNode extends SqlNode implements SelectExpression {
final String sizeColumn = sizeColumns[0];
final StringBuilder buffer = new StringBuilder( "(select " ).append( sizeColumn );
buffer.append( " from " ).append( collectionDescriptor.getTableName() ).append( " as " ).append( collectionTableAlias );
buffer.append( " from " ).append( collectionDescriptor.getTableName() ).append( " " ).append( collectionTableAlias );
buffer.append( " where " );
boolean firstPass = true;

View File

@ -344,12 +344,6 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Found mapping document in jar: %s", id = 109)
void foundMappingDocument(String name);
@LogMessage(level = ERROR)
@Message(value = "Getters of lazy classes cannot be final: %s.%s", id = 112)
void gettersOfLazyClassesCannotBeFinal(
String entityName,
String name);
@LogMessage(level = WARN)
@Message(value = "GUID identifier generated: %s", id = 113)
void guidGenerated(String result);
@ -778,12 +772,6 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Sessions opened: %s", id = 242)
void sessionsOpened(long sessionOpenCount);
@LogMessage(level = ERROR)
@Message(value = "Setters of lazy classes cannot be final: %s.%s", id = 243)
void settersOfLazyClassesCannotBeFinal(
String entityName,
String name);
@LogMessage(level = WARN)
@Message(value = "@Sort not allowed for an indexed collection, annotation ignored.", id = 244)
void sortAnnotationIndexedCollection();

View File

@ -322,12 +322,10 @@ public class ResultSetProcessingContextImpl implements ResultSetProcessingContex
createSubselects();
if ( hydratedEntityRegistrationList != null ) {
hydratedEntityRegistrationList.clear();
hydratedEntityRegistrationList = null;
}
if ( subselectLoadableEntityKeyMap != null ) {
subselectLoadableEntityKeyMap.clear();
subselectLoadableEntityKeyMap = null;
}
}

View File

@ -11,6 +11,7 @@ import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
@ -84,14 +85,21 @@ public final class ProxyFactoryHelper {
Class clazz = persistentClass.getMappedClass();
while ( properties.hasNext() ) {
Property property = (Property) properties.next();
Method method = property.getGetter( clazz ).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.gettersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
}
method = property.getSetter( clazz ).getMethod();
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
LOG.settersOfLazyClassesCannotBeFinal( persistentClass.getEntityName(), property.getName() );
}
validateGetterSetterMethodProxyability( "Getter", property.getGetter( clazz ).getMethod() );
validateGetterSetterMethodProxyability( "Setter", property.getSetter( clazz ).getMethod() );
}
}
public static void validateGetterSetterMethodProxyability(String getterOrSetter, Method method ) {
if ( method != null && Modifier.isFinal( method.getModifiers() ) ) {
throw new HibernateException(
String.format(
"%s methods of lazy classes cannot be final: %s#%s",
getterOrSetter,
method.getDeclaringClass().getName(),
method.getName()
)
);
}
}

View File

@ -88,13 +88,17 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
final Set<Class> proxyInterfaces = ProxyFactoryHelper.extractProxyInterfaces( persistentClass, entityName );
ProxyFactoryHelper.validateProxyability( persistentClass );
Method proxyGetIdentifierMethod = ProxyFactoryHelper.extractProxyGetIdentifierMethod( idGetter, proxyInterface );
Method proxySetIdentifierMethod = ProxyFactoryHelper.extractProxySetIdentifierMethod( idSetter, proxyInterface );
ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter );
try {
ProxyFactoryHelper.validateGetterSetterMethodProxyability( "Getter", proxyGetIdentifierMethod );
ProxyFactoryHelper.validateGetterSetterMethodProxyability( "Setter", proxySetIdentifierMethod );
ProxyFactoryHelper.validateProxyability( persistentClass );
pf.postInstantiate(
entityName,
mappedClass,

View File

@ -13,8 +13,8 @@ import org.junit.Test;
import java.sql.SQLException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Unit test of the {@link StandardDialectResolver} class.
@ -44,7 +44,7 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
@Test
public void testResolveDialectInternalForSQLServer2012()
throws SQLException {
runSQLServerDialectTest( 11, SQLServer2008Dialect.class );
runSQLServerDialectTest( 11, SQLServer2012Dialect.class );
}
@Test
@ -93,7 +93,7 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
@Test
public void testResolveDialectInternalForPostgres92() throws SQLException {
runPostgresDialectTest( 9, 2, PostgreSQL9Dialect.class );
runPostgresDialectTest( 9, 2, PostgreSQL92Dialect.class );
}
@Test
@ -131,6 +131,17 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
runMySQLDialectTest( 5, 7, MySQL57Dialect.class );
}
@Test
public void testResolveDialectInternalForMySQL6() throws SQLException {
runMySQLDialectTest( 6, 0, MySQL57Dialect.class );
}
@Test
public void testResolveDialectInternalForMySQL7() throws SQLException {
runMySQLDialectTest( 7, 0, MySQL57Dialect.class );
}
@Test
public void testResolveDialectInternalForMySQL8() throws SQLException {
runMySQLDialectTest( 8, 0, MySQL8Dialect.class );
@ -188,8 +199,11 @@ public class StandardDialectResolverTest extends BaseUnitTestCase {
String dbms = builder.toString();
assertNotNull( "Dialect for " + dbms + " should not be null", dialect );
assertTrue( "Dialect for " + dbms + " should be "
+ expectedDialect.getSimpleName(),
expectedDialect.isInstance( dialect ) );
// Make sure to test that the actual dialect class is as expected
// (not just an instance of the expected dialect.
assertEquals( "Dialect for " + dbms + " should be " + expectedDialect.getSimpleName(),
expectedDialect,
dialect.getClass()
);
}
}

View File

@ -0,0 +1,502 @@
/*
* 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.proxy;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Version;
import org.hibernate.Hibernate;
import org.hibernate.ObjectNotFoundException;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Gail Badner
*/
@TestForIssue( jiraKey = "HHH-13891" )
public class FinalGetterSetterTest extends BaseNonConfigCoreFunctionalTestCase {
@Test
public void testEntityWithFinalClass() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalClass.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalClass.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalClass entity = new EntityWithFinalClass();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalClass entity = session.load( EntityWithFinalClass.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalIdGetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalIdGetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalIdGetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalIdGetter entity = new EntityWithFinalIdGetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalIdGetter entity = session.load( EntityWithFinalIdGetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalIdSetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalIdSetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalIdSetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalIdSetter entity = new EntityWithFinalIdSetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalIdSetter entity = session.load( EntityWithFinalIdSetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalVersionGetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalVersionGetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalVersionGetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalVersionGetter entity = new EntityWithFinalVersionGetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalVersionGetter entity = session.load( EntityWithFinalVersionGetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalVersionSetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalVersionSetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalVersionSetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalVersionSetter entity = new EntityWithFinalVersionSetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalVersionSetter entity = session.load( EntityWithFinalVersionSetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalPropertyGetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalPropertyGetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalPropertyGetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalPropertyGetter entity = new EntityWithFinalPropertyGetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalPropertyGetter entity = session.load( EntityWithFinalPropertyGetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Test
public void testEntityWithFinalPropertySetter() {
doInHibernate( this::sessionFactory, session -> {
assertNull( session.get( EntityWithFinalPropertySetter.class, 999 ) );
});
try {
doInHibernate( this::sessionFactory, session -> {
session.load( EntityWithFinalPropertySetter.class, 999 );
});
fail( "Should have thrown ObjectNotFoundException" );
}
catch (ObjectNotFoundException expected) {
}
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalPropertySetter entity = new EntityWithFinalPropertySetter();
entity.id = 1;
entity.name = "An Entity";
session.persist( entity );
});
doInHibernate( this::sessionFactory, session -> {
final EntityWithFinalPropertySetter entity = session.load( EntityWithFinalPropertySetter.class, 1 );
assertNotNull( entity );
assertTrue( Hibernate.isInitialized( entity ) );
});
}
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
EntityWithFinalClass.class,
EntityWithFinalIdGetter.class,
EntityWithFinalIdSetter.class,
EntityWithFinalVersionGetter.class,
EntityWithFinalVersionSetter.class,
EntityWithFinalPropertyGetter.class,
EntityWithFinalPropertySetter.class
};
}
@Entity( name = "EntityWithFinalClass")
public static final class EntityWithFinalClass {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public final int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalIdGetter")
public static class EntityWithFinalIdGetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public final int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalIdSetter")
public static class EntityWithFinalIdSetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalVersionGetter")
public static class EntityWithFinalVersionGetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public final int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalVersionSetter")
public static class EntityWithFinalVersionSetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public final void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalPropertyGetter")
public static class EntityWithFinalPropertyGetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public final String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Entity( name = "EntityWithFinalPropertySetter")
public static class EntityWithFinalPropertySetter {
@Id
private int id;
@Version
@Column(name = "ver")
private int version;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public String getName() {
return name;
}
public final void setName(String name) {
this.name = name;
}
}
}