From d89b28e1a9891d5a7eabb53bcc74844c86eefa19 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 13 Dec 2021 19:12:37 +0100 Subject: [PATCH] Re-enabled additional tests --- .../StoreProcedureOutParameterByNameTest.java | 5 +- ...reProcedureOutParameterByPositionTest.java | 5 +- ...cedureRefCursorOutParameterByNameTest.java | 5 +- ...reRefCursorOutParameterByPositionTest.java | 5 +- .../access/jpa/AccessMappingTest.java | 278 ++++++++++++++++++ ...toredProcedureNullParameterByNameTest.java | 9 +- .../paths/EntityModeMapJoinsTest.java | 63 ---- .../access/jpa/AccessMappingTest.java | 264 ----------------- 8 files changed, 298 insertions(+), 336 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java (96%) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/bootstrap/binding/annotations/access/jpa/AccessMappingTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/jpa/test/criteria/paths/EntityModeMapJoinsTest.java delete mode 100644 hibernate-core/src/test_legacy/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java index f589baef08..0fa87c2029 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByNameTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.jpa.procedure; +package org.hibernate.orm.test.jpa.procedure; import java.sql.Connection; import java.sql.SQLException; @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Test; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -41,7 +42,7 @@ import static org.junit.Assert.fail; * @author Gail Badner */ @TestForIssue(jiraKey = "HHH-10756") -@RequiresDialect(Oracle10gDialect.class) +@RequiresDialect(OracleDialect.class) public class StoreProcedureOutParameterByNameTest extends BaseEntityManagerFunctionalTestCase { EntityManagerFactory entityManagerFactory; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java index aef1f8b550..7fc9b68a99 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureOutParameterByPositionTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.jpa.procedure; +package org.hibernate.orm.test.jpa.procedure; import java.sql.Connection; import java.sql.SQLException; @@ -25,6 +25,7 @@ import org.junit.Before; import org.junit.Test; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -41,7 +42,7 @@ import static org.junit.Assert.fail; * @author Gail Badner */ @TestForIssue(jiraKey = "HHH-10756") -@RequiresDialect(Oracle10gDialect.class) +@RequiresDialect(OracleDialect.class) public class StoreProcedureOutParameterByPositionTest extends BaseEntityManagerFunctionalTestCase { EntityManagerFactory entityManagerFactory; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java index 7dd43f32d9..80747d54d0 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByNameTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.jpa.procedure; +package org.hibernate.orm.test.jpa.procedure; import java.sql.Connection; import java.sql.SQLException; @@ -21,6 +21,7 @@ import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.Table; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -37,7 +38,7 @@ import static org.junit.Assert.fail; * @author Andrea Boriero */ @TestForIssue(jiraKey = "HHH-9286") -@RequiresDialect(Oracle10gDialect.class) +@RequiresDialect(OracleDialect.class) public class StoreProcedureRefCursorOutParameterByNameTest extends BaseEntityManagerFunctionalTestCase { EntityManagerFactory entityManagerFactory; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java index 5ec9167b15..3483bde775 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/procedure/StoreProcedureRefCursorOutParameterByPositionTest.java @@ -4,7 +4,7 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ -package org.hibernate.test.jpa.procedure; +package org.hibernate.orm.test.jpa.procedure; import java.sql.Connection; import java.sql.SQLException; @@ -21,6 +21,7 @@ import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.Table; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -37,7 +38,7 @@ import static org.junit.Assert.fail; * @author Andrea Boriero */ @TestForIssue(jiraKey = "HHH-9286") -@RequiresDialect(Oracle10gDialect.class) +@RequiresDialect(OracleDialect.class) public class StoreProcedureRefCursorOutParameterByPositionTest extends BaseEntityManagerFunctionalTestCase { EntityManagerFactory entityManagerFactory; diff --git a/hibernate-core/src/test/java/org/hibernate/test/bootstrap/binding/annotations/access/jpa/AccessMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/bootstrap/binding/annotations/access/jpa/AccessMappingTest.java new file mode 100644 index 0000000000..d23a221a24 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/bootstrap/binding/annotations/access/jpa/AccessMappingTest.java @@ -0,0 +1,278 @@ +/* + * 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 . + */ +package org.hibernate.test.bootstrap.binding.annotations.access.jpa; + +import org.hibernate.MappingException; +import org.hibernate.SessionFactory; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Animal; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Being; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course1; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course2; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course3; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course4; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course5; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course6; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course7; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Course8; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Horse; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Person; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.Student; +import org.hibernate.orm.test.bootstrap.binding.annotations.access.jpa.User; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.property.access.spi.GetterFieldImpl; +import org.hibernate.property.access.spi.GetterMethodImpl; +import org.hibernate.service.ServiceRegistry; + +import org.hibernate.testing.ServiceRegistryBuilder; +import org.hibernate.testing.TestForIssue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +/** + * Tests verifying the correct behaviour for the usage of {@code @jakarta.persistence.Access}. + * + * @author Hardy Ferentschik + */ +@SuppressWarnings({ "deprecation" }) +public class AccessMappingTest { + private ServiceRegistry serviceRegistry; + + @Before + public void setUp() { + serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); + } + + @After + public void tearDown() { + if ( serviceRegistry != null ) { + ServiceRegistryBuilder.destroy( serviceRegistry ); + } + } + + @Test + public void testInconsistentAnnotationPlacement() { + Configuration cfg = new Configuration(); + cfg.addAnnotatedClass( Course1.class ); + cfg.addAnnotatedClass( Student.class ); + SessionFactory sf = null; + try { + sf = cfg.buildSessionFactory( serviceRegistry ); + fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); + } + catch (MappingException e) { + // success + } + finally { + if ( sf != null ) { + sf.close(); + } + } + } + + @Test + public void testFieldAnnotationPlacement() { + Configuration cfg = new Configuration(); + Class classUnderTest = Course6.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Student.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Field access should be used.", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testPropertyAnnotationPlacement() { + Configuration cfg = new Configuration(); + Class classUnderTest = Course7.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Student.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Property access should be used.", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception { + Configuration cfg = new Configuration(); + Class classUnderTest = Course2.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Student.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Property access should be used.", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testExplicitPropertyAccessAnnotationsOnField() { + Configuration cfg = new Configuration(); + cfg.addAnnotatedClass( Course4.class ); + cfg.addAnnotatedClass( Student.class ); + SessionFactory sf = null; + try { + sf = cfg.buildSessionFactory( serviceRegistry ); + fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); + } + catch (MappingException e) { + // success + } + finally { + if ( sf != null ) { + sf.close(); + } + } + } + + @Test + public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() { + Configuration cfg = new Configuration(); + Class classUnderTest = Course3.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Student.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Field access should be used.", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl + ); + + assertTrue( + "Property access should be used.", + entityPersister.getAttributeMapping( 0 ).getPropertyAccess().getGetter() instanceof GetterMethodImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() { + Configuration cfg = new Configuration(); + Class classUnderTest = Course5.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Student.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Field access should be used.", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl + ); + + assertTrue( + "Property access should be used.", + entityPersister.getAttributeMapping( 0 ).getPropertyAccess().getGetter() instanceof GetterMethodImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testDefaultFieldAccessIsInherited() { + Configuration cfg = new Configuration(); + Class classUnderTest = User.class; + cfg.addAnnotatedClass( classUnderTest ); + cfg.addAnnotatedClass( Person.class ); + cfg.addAnnotatedClass( Being.class ); + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + final EntityPersister entityPersister = factory.getEntityPersister( classUnderTest.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Field access should be used since the default access mode gets inherited", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl + ); + } + finally { + factory.close(); + } + } + + @Test + public void testDefaultPropertyAccessIsInherited() { + Configuration cfg = new Configuration(); + cfg.addAnnotatedClass( Horse.class ); + cfg.addAnnotatedClass( Animal.class ); + + SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); + try { + EntityPersister entityPersister = factory.getEntityPersister( Animal.class.getName() ); + final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping(); + + assertTrue( + "Property access should be used since explicity configured via @Access", + identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl + ); + + entityPersister = factory.getEntityPersister( Horse.class.getName() ); + + assertTrue( + "Field access should be used since the default access mode gets inherited", + entityPersister.getAttributeMapping( 0 ).getPropertyAccess().getGetter() instanceof GetterFieldImpl + ); + } + finally { + factory.close(); + } + } + + @TestForIssue(jiraKey = "HHH-5004") + @Test + public void testAccessOnClassAndId() { + Configuration cfg = new Configuration(); + cfg.addAnnotatedClass( Course8.class ); + cfg.addAnnotatedClass( Student.class ); + cfg.buildSessionFactory( serviceRegistry ).close(); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoredProcedureNullParameterByNameTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoredProcedureNullParameterByNameTest.java index b7556456b9..c25291432b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoredProcedureNullParameterByNameTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/procedure/StoredProcedureNullParameterByNameTest.java @@ -26,6 +26,7 @@ import org.junit.Before; import org.junit.Test; import org.hibernate.dialect.Oracle10gDialect; +import org.hibernate.dialect.OracleDialect; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.spi.SessionFactoryImplementor; @@ -41,7 +42,7 @@ import static org.junit.Assert.fail; * @author Gail Badner */ @TestForIssue(jiraKey = "HHH-10761") -@RequiresDialect(Oracle10gDialect.class) +@RequiresDialect(OracleDialect.class) public class StoredProcedureNullParameterByNameTest extends BaseEntityManagerFunctionalTestCase { EntityManagerFactory entityManagerFactory; @@ -50,6 +51,12 @@ public class StoredProcedureNullParameterByNameTest extends BaseEntityManagerFun return new Class[] {User.class}; } +// @Override +// @SuppressWarnings({ "unchecked" }) +// protected void addConfigOptions(Map options) { +// options.put( org.hibernate.cfg.AvailableSettings.PROCEDURE_NULL_PARAM_PASSING, "true" ); +// } + @Before public void startUp() { entityManagerFactory = getOrCreateEntityManager().getEntityManagerFactory(); diff --git a/hibernate-core/src/test_legacy/org/hibernate/jpa/test/criteria/paths/EntityModeMapJoinsTest.java b/hibernate-core/src/test_legacy/org/hibernate/jpa/test/criteria/paths/EntityModeMapJoinsTest.java deleted file mode 100644 index f856f0734d..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/jpa/test/criteria/paths/EntityModeMapJoinsTest.java +++ /dev/null @@ -1,63 +0,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 - */ -package org.hibernate.jpa.test.criteria.paths; - -import java.util.Map; - -import jakarta.persistence.criteria.CriteriaBuilder; -import jakarta.persistence.criteria.JoinType; -import jakarta.persistence.metamodel.Attribute; -import jakarta.persistence.metamodel.Bindable; -import jakarta.persistence.metamodel.SingularAttribute; -import jakarta.persistence.metamodel.Type; - -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - -import org.junit.Test; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.withSettings; - -/** - * @author Andrea Boriero - */ -public class EntityModeMapJoinsTest extends BaseEntityManagerFunctionalTestCase { - @Override - protected String[] getMappings() { - return new String[] { - getClass().getPackage().getName().replace( '.', '/' ) + "/PolicyAndDistribution.hbm.xml" - }; - } - - @Override - protected void addConfigOptions(Map options) { - super.addConfigOptions( options ); - - // make sure that dynamic-map mode entity types are returned in the metamodel. - options.put( AvailableSettings.JPA_METAMODEL_POPULATION, "enabled" ); - } - - /** - * When building a join from a non-class based entity (EntityMode.MAP), make sure you get the Bindable from - * the SingularAttribute as the join model. If you don't, you'll get the first non-classed based entity - * you added to your configuration. Regression for HHH-9142. - */ - @Test - public void testEntityModeMapJoins() throws Exception { - CriteriaBuilder criteriaBuilder = mock( CriteriaBuilder.class); - PathSource pathSource = mock( PathSource.class); - SingularAttribute joinAttribute = mock( SingularAttribute.class); - when(joinAttribute.getPersistentAttributeType()).thenReturn( Attribute.PersistentAttributeType.MANY_TO_ONE); - Type joinType = mock( Type.class, withSettings().extraInterfaces( Bindable.class)); - when(joinAttribute.getType()).thenReturn(joinType); - SingularAttributeJoin join = new SingularAttributeJoin( criteriaBuilder, null, pathSource, joinAttribute, JoinType.LEFT); - - assertEquals( joinType, join.getModel()); - } -} diff --git a/hibernate-core/src/test_legacy/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java b/hibernate-core/src/test_legacy/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java deleted file mode 100644 index 4e2121fc28..0000000000 --- a/hibernate-core/src/test_legacy/org/hibernate/test/annotations/access/jpa/AccessMappingTest.java +++ /dev/null @@ -1,264 +0,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 . - */ -package org.hibernate.test.annotations.access.jpa; - -import org.hibernate.MappingException; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.property.access.spi.GetterFieldImpl; -import org.hibernate.property.access.spi.GetterMethodImpl; -import org.hibernate.service.ServiceRegistry; -import org.hibernate.tuple.entity.EntityTuplizer; - -import org.hibernate.testing.ServiceRegistryBuilder; -import org.hibernate.testing.TestForIssue; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - - -/** - * Tests verifying the correct behaviour for the usage of {@code @jakarta.persistence.Access}. - * - * @author Hardy Ferentschik - */ -@SuppressWarnings({ "deprecation" }) -public class AccessMappingTest { - private ServiceRegistry serviceRegistry; - - @Before - public void setUp() { - serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() ); - } - - @After - public void tearDown() { - if ( serviceRegistry != null ) { - ServiceRegistryBuilder.destroy( serviceRegistry ); - } - } - - @Test - public void testInconsistentAnnotationPlacement() throws Exception { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass( Course1.class ); - cfg.addAnnotatedClass( Student.class ); - SessionFactory sf = null; - try { - sf = cfg.buildSessionFactory( serviceRegistry ); - fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); - } - catch (MappingException e) { - // success - } - finally { - if ( sf != null ) { - sf.close(); - } - } - } - - @Test - public void testFieldAnnotationPlacement() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = Course6.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Student.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Field access should be used.", - tuplizer.getIdentifierGetter() instanceof GetterFieldImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testPropertyAnnotationPlacement() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = Course7.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Student.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Property access should be used.", - tuplizer.getIdentifierGetter() instanceof GetterMethodImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testExplicitPropertyAccessAnnotationsOnProperty() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = Course2.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Student.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Property access should be used.", - tuplizer.getIdentifierGetter() instanceof GetterMethodImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testExplicitPropertyAccessAnnotationsOnField() throws Exception { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass( Course4.class ); - cfg.addAnnotatedClass( Student.class ); - SessionFactory sf= null; - try { - sf = cfg.buildSessionFactory( serviceRegistry ); - fail( "@Id and @OneToMany are not placed consistently in test entities. SessionFactory creation should fail." ); - } - catch (MappingException e) { - // success - } - finally { - if ( sf != null ) { - sf.close(); - } - } - } - - @Test - public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = Course3.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Student.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Field access should be used.", - tuplizer.getIdentifierGetter() instanceof GetterFieldImpl - ); - - assertTrue( - "Property access should be used.", - tuplizer.getGetter( 0 ) instanceof GetterMethodImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = Course5.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Student.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Field access should be used.", - tuplizer.getIdentifierGetter() instanceof GetterFieldImpl - ); - - assertTrue( - "Property access should be used.", - tuplizer.getGetter( 0 ) instanceof GetterMethodImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testDefaultFieldAccessIsInherited() throws Exception { - Configuration cfg = new Configuration(); - Class classUnderTest = User.class; - cfg.addAnnotatedClass( classUnderTest ); - cfg.addAnnotatedClass( Person.class ); - cfg.addAnnotatedClass( Being.class ); - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( classUnderTest.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Field access should be used since the default access mode gets inherited", - tuplizer.getIdentifierGetter() instanceof GetterFieldImpl - ); - } - finally { - factory.close(); - } - } - - @Test - public void testDefaultPropertyAccessIsInherited() throws Exception { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass( Horse.class ); - cfg.addAnnotatedClass( Animal.class ); - - SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory( serviceRegistry ); - try { - EntityTuplizer tuplizer = factory.getEntityPersister( Animal.class.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Property access should be used since explicity configured via @Access", - tuplizer.getIdentifierGetter() instanceof GetterMethodImpl - ); - - tuplizer = factory.getEntityPersister( Horse.class.getName() ) - .getEntityMetamodel() - .getTuplizer(); - assertTrue( - "Field access should be used since the default access mode gets inherited", - tuplizer.getGetter( 0 ) instanceof GetterFieldImpl - ); - } - finally { - factory.close(); - } - } - - @TestForIssue(jiraKey = "HHH-5004") - @Test - public void testAccessOnClassAndId() throws Exception { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass( Course8.class ); - cfg.addAnnotatedClass( Student.class ); - cfg.buildSessionFactory( serviceRegistry ).close(); - } -}