From e3947b3b1cc43f8a4e58e34424cc19d6c927aefc Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 25 Nov 2020 15:15:34 +0100 Subject: [PATCH] Re-enabled additional tests and fix issues with IdClass --- .../userguide/pc/DynamicUpdateTest.java | 5 - .../internal/MappingModelCreationHelper.java | 30 +- .../NonAggregatedIdentifierMappingImpl.java | 5 +- .../domain/AbstractIdentifiableType.java | 5 + .../test/annotations/id/AndFormulaTest.java | 27 +- .../orm/test/annotations/id/EnumIdTest.java | 66 ++++ .../orm/test/annotations/id/IdClassTest.java | 47 +++ .../orm/test/annotations/id/IdTest.java | 353 +++++++++++++++++ .../id/JoinColumnOverrideTest.java | 27 +- .../test/annotations/id/UUIDGenerator.java | 2 +- .../test/annotations/id/entities/Ball.java | 2 +- .../annotations/id/entities/BreakDance.java | 2 +- .../test/annotations/id/entities/Bunny.java | 5 +- .../annotations/id/entities/Computer.java | 2 +- .../annotations/id/entities/Department.java | 2 +- .../test/annotations/id/entities/Dog.java | 2 +- .../test/annotations/id/entities/FirTree.java | 2 +- .../annotations/id/entities/Footballer.java | 2 +- .../annotations/id/entities/FootballerPk.java | 2 +- .../annotations/id/entities/Furniture.java | 2 +- .../annotations/id/entities/GoalKeeper.java | 2 +- .../test/annotations/id/entities/Home.java | 2 +- .../test/annotations/id/entities/Hotel.java | 2 +- .../annotations/id/entities/Location.java | 2 +- .../id/entities/MilitaryBuilding.java | 2 +- .../test/annotations/id/entities/Monkey.java | 2 +- .../test/annotations/id/entities/Phone.java | 2 +- .../test/annotations/id/entities/Planet.java | 2 +- .../id/entities/PlanetCheatSheet.java | 2 +- .../annotations/id/entities/PointyTooth.java | 4 +- .../test/annotations/id/entities/Shoe.java | 2 +- .../annotations/id/entities/SoundSystem.java | 2 +- .../test/annotations/id/entities/Store.java | 2 +- .../test/annotations/id/entities/Tower.java | 2 +- .../test/annotations/id/entities/Tree.java | 2 +- .../annotations/id/entities/TwinkleToes.java | 5 +- .../id/generationmappings/AutoEntity.java | 2 +- .../CompleteSequenceEntity.java | 2 +- .../DedicatedSequenceEntity1.java | 2 +- .../DedicatedSequenceEntity2.java | 2 +- .../MinimalSequenceEntity.java | 2 +- .../MinimalTableEntity.java | 2 +- .../NewGeneratorMappingsTest.java | 72 ++-- .../id/generationmappings/package-info.java | 2 +- .../test/annotations/id/package-info.java | 2 +- .../annotations/id/sequences/EnumIdTest.java | 64 ++++ .../id/sequences/HibernateSequenceTest.java | 66 ++++ .../annotations/id/sequences/IdClassTest.java | 6 +- .../test/annotations/id/sequences/IdTest.java | 344 +++++++++++++++++ .../id/sequences/JoinColumnOverrideTest.java | 27 +- .../id/sequences/UUIDGenerator.java | 2 +- .../id/sequences/entities/Ball.java | 2 +- .../id/sequences/entities/BreakDance.java | 2 +- .../id/sequences/entities/Bunny.java | 4 +- .../id/sequences/entities/Computer.java | 2 +- .../id/sequences/entities/Department.java | 2 +- .../id/sequences/entities/Dog.java | 2 +- .../id/sequences/entities/FirTree.java | 2 +- .../id/sequences/entities/Footballer.java | 2 +- .../id/sequences/entities/FootballerPk.java | 2 +- .../id/sequences/entities/Furniture.java | 2 +- .../id/sequences/entities/GoalKeeper.java | 2 +- .../entities/HibernateSequenceEntity.java | 2 +- .../id/sequences/entities/Home.java | 2 +- .../id/sequences/entities/Location.java | 2 +- .../sequences/entities/MilitaryBuilding.java | 2 +- .../id/sequences/entities/Monkey.java | 2 +- .../id/sequences/entities/Phone.java | 2 +- .../id/sequences/entities/Planet.java | 2 +- .../sequences/entities/PlanetCheatSheet.java | 2 +- .../id/sequences/entities/PointyTooth.java | 4 +- .../id/sequences/entities/Shoe.java | 2 +- .../id/sequences/entities/SoundSystem.java | 2 +- .../id/sequences/entities/Store.java | 2 +- .../id/sequences/entities/Tower.java | 2 +- .../id/sequences/entities/Tree.java | 2 +- .../id/sequences/entities/TwinkleToes.java | 4 +- .../id/sequences/package-info.java | 2 +- .../test/annotations/idclass/DomainAdmin.java | 4 +- .../annotations/idclass/DomainAdminId.java | 2 +- .../idclass/IdClassCompositePKTest.java | 45 +++ .../idclass/IdClassMappedSuperclassTest.java | 83 ++-- .../idclass/xml/HabitatSpeciesLink.java | 2 +- .../idclass/xml/IdClassXmlTest.java | 46 +++ .../test/annotations/id/EnumIdTest.java | 66 ---- .../test/annotations/id/IdClassTest.java | 48 --- .../hibernate/test/annotations/id/IdTest.java | 360 ------------------ .../annotations/id/sequences/EnumIdTest.java | 65 ---- .../id/sequences/HibernateSequenceTest.java | 75 ---- .../test/annotations/id/sequences/IdTest.java | 350 ----------------- .../idclass/IdClassCompositePKTest.java | 45 --- .../idclass/xml/IdClassXmlTest.java | 52 --- .../test/annotations/id/sequences/orm.xml | 0 .../idclass/xml/HabitatSpeciesLink.xml | 6 +- .../orm/junit/DomainModelExtension.java | 2 +- .../testing/orm/junit/SessionFactory.java | 2 + .../orm/junit/SessionFactoryExtension.java | 18 +- 97 files changed, 1260 insertions(+), 1295 deletions(-) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/AndFormulaTest.java (72%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/EnumIdTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdClassTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdTest.java rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/JoinColumnOverrideTest.java (71%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/UUIDGenerator.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Ball.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/BreakDance.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Bunny.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Computer.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Department.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Dog.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/FirTree.java (86%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Footballer.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/FootballerPk.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Furniture.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/GoalKeeper.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Home.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Hotel.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Location.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/MilitaryBuilding.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Monkey.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Phone.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Planet.java (85%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/PlanetCheatSheet.java (97%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/PointyTooth.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Shoe.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/SoundSystem.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Store.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Tower.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/Tree.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/entities/TwinkleToes.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/AutoEntity.java (89%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/CompleteSequenceEntity.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/MinimalSequenceEntity.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/MinimalTableEntity.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java (70%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/generationmappings/package-info.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/package-info.java (92%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/EnumIdTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/HibernateSequenceTest.java rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/IdClassTest.java (84%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdTest.java rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/JoinColumnOverrideTest.java (69%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/UUIDGenerator.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Ball.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/BreakDance.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Bunny.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Computer.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Department.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Dog.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/FirTree.java (86%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Footballer.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/FootballerPk.java (95%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Furniture.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/GoalKeeper.java (89%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/HibernateSequenceEntity.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Home.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Location.java (94%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/MilitaryBuilding.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Monkey.java (89%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Phone.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Planet.java (85%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/PlanetCheatSheet.java (96%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/PointyTooth.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Shoe.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/SoundSystem.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Store.java (93%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Tower.java (89%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/Tree.java (90%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/entities/TwinkleToes.java (92%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/id/sequences/package-info.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/idclass/DomainAdmin.java (91%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/idclass/DomainAdminId.java (96%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassCompositePKTest.java rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/idclass/IdClassMappedSuperclassTest.java (57%) rename hibernate-core/src/test/java/org/hibernate/{ => orm}/test/annotations/idclass/xml/HabitatSpeciesLink.java (98%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/IdClassXmlTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassCompositePKTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java rename hibernate-core/src/test/resources/org/hibernate/{ => orm}/test/annotations/id/sequences/orm.xml (100%) rename hibernate-core/src/test/resources/org/hibernate/{ => orm}/test/annotations/idclass/xml/HabitatSpeciesLink.xml (77%) diff --git a/documentation/src/test/java/org/hibernate/userguide/pc/DynamicUpdateTest.java b/documentation/src/test/java/org/hibernate/userguide/pc/DynamicUpdateTest.java index d17521b62b..002ba26fc6 100644 --- a/documentation/src/test/java/org/hibernate/userguide/pc/DynamicUpdateTest.java +++ b/documentation/src/test/java/org/hibernate/userguide/pc/DynamicUpdateTest.java @@ -7,17 +7,12 @@ package org.hibernate.userguide.pc; import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.Embedded; import javax.persistence.Entity; -import javax.persistence.GeneratedValue; import javax.persistence.Id; import org.hibernate.annotations.DynamicUpdate; -import org.hibernate.annotations.Target; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.test.annotations.id.entities.Shoe; import org.junit.Test; import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 8ca48bf75b..b734f0b16a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -153,10 +153,10 @@ public class MappingModelCreationHelper { PersistentClass bootEntityDescriptor, BiConsumer idSubAttributeConsumer, MappingModelCreationProcess creationProcess) { - final Component bootCompositeDescriptor = (Component) bootEntityDescriptor.getIdentifier(); + final Component bootIdClassComponent = (Component) bootEntityDescriptor.getIdentifier(); final EmbeddableMappingType embeddableMappingType = EmbeddableMappingType.from( - bootCompositeDescriptor, + bootIdClassComponent, cidType, attributeMappingType -> { final SessionFactoryImplementor sessionFactory = creationProcess.getCreationContext().getSessionFactory(); @@ -167,15 +167,19 @@ public class MappingModelCreationHelper { final StateArrayContributorMetadataAccess attributeMetadataAccess = getStateArrayContributorMetadataAccess( propertyAccess ); - final Component idClass = bootEntityDescriptor.getIdentifierMapper(); - Component bootIdDescriptor = bootEntityDescriptor.getDeclaredIdentifierMapper(); - if ( bootIdDescriptor == null ) { - bootIdDescriptor = (Component) bootEntityDescriptor.getIdentifier(); - } - final List idAttributeMappings = new ArrayList<>( bootIdDescriptor.getPropertySpan() ); + Component bootComponentDescriptor = bootEntityDescriptor.getIdentifierMapper(); + final List idAttributeMappings; + final Iterator bootIdSubPropertyItr; + if ( bootComponentDescriptor == null ) { + idAttributeMappings = new ArrayList<>( bootIdClassComponent.getPropertySpan() ); + bootIdSubPropertyItr = bootIdClassComponent.getPropertyIterator(); + + } + else { + idAttributeMappings = new ArrayList<>( bootComponentDescriptor.getPropertySpan() ); + bootIdSubPropertyItr = bootComponentDescriptor.getPropertyIterator(); + } - //noinspection unchecked - final Iterator bootIdSubPropertyItr = bootIdDescriptor.getPropertyIterator(); int columnsConsumedSoFar = 0; while ( bootIdSubPropertyItr.hasNext() ) { @@ -245,7 +249,7 @@ public class MappingModelCreationHelper { } idAttributeMappings.add( idSubAttribute ); - if ( idClass == null ) { + if ( bootComponentDescriptor == null ) { idSubAttributeConsumer.accept( idSubAttribute.getAttributeName(), idSubAttribute ); } } @@ -257,8 +261,8 @@ public class MappingModelCreationHelper { attributeMetadataAccess, rootTableName, rootTableKeyColumnNames, - bootIdDescriptor, - bootCompositeDescriptor, + bootIdClassComponent, + bootComponentDescriptor, creationProcess ); }, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java index 142b7849fa..3f30b1d87f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/NonAggregatedIdentifierMappingImpl.java @@ -48,8 +48,8 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif StateArrayContributorMetadataAccess attributeMetadataAccess, String rootTableName, String[] rootTableKeyColumnNames, - Component bootCidDescriptor, Component bootIdClassDescriptor, + Component bootCidDescriptor, MappingModelCreationProcess creationProcess) { // todo (6.0) : handle MapsId super( @@ -78,9 +78,6 @@ public class NonAggregatedIdentifierMappingImpl extends AbstractCompositeIdentif @Override public Object getIdentifier(Object entity, SharedSessionContractImplementor session) { - if ( entity instanceof HibernateProxy ) { - return ( (HibernateProxy) entity ).getHibernateLazyInitializer().getIdentifier(); - } final Serializable disassemble = bootCidDescriptor.getType().disassemble( entity, session, null ); return bootIdClassDescriptor.getType().assemble( disassemble, session, null ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java index 96343cdafa..2f2cd9401e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java @@ -346,6 +346,11 @@ public abstract class AbstractIdentifiableType } } + @Override + public void applyIdClassAttributes(Set idClassAttributes) { + applyNonAggregatedIdAttributes( idClassAttributes ); + } + @Override @SuppressWarnings("unchecked") public void applyVersionAttribute(SingularPersistentAttribute versionAttribute) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/AndFormulaTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/AndFormulaTest.java similarity index 72% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/AndFormulaTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/AndFormulaTest.java index 04d17124bc..6a43ffdccc 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/AndFormulaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/AndFormulaTest.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.annotations.id; +package org.hibernate.orm.test.annotations.id; import javax.persistence.Entity; import javax.persistence.Id; @@ -15,30 +15,33 @@ import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.CannotForceNonNullableException; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.hibernate.testing.junit5.BaseUnitTest; +import org.hibernate.testing.orm.junit.ServiceRegistry; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; /** * Originally developed for HHH-9807 - better error message on combination of {@code @Id} + {@code @Formula} * * @author Steve Ebersole */ -public class AndFormulaTest extends BaseUnitTestCase { +@ServiceRegistry +public class AndFormulaTest extends BaseUnitTest { private static StandardServiceRegistry ssr; - @BeforeClass - public static void prepareServiceRegistry() { + @BeforeEach + public void prepareServiceRegistry() { ssr = new StandardServiceRegistryBuilder().build(); } - @AfterClass - public static void releaseServiceRegistry() { + @AfterEach + public void releaseServiceRegistry() { if ( ssr != null ) { StandardServiceRegistryBuilder.destroy( ssr ); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/EnumIdTest.java new file mode 100644 index 0000000000..1546baf937 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/EnumIdTest.java @@ -0,0 +1,66 @@ +/* + * 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.orm.test.annotations.id; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.entities.Planet; +import org.hibernate.orm.test.annotations.id.entities.PlanetCheatSheet; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + + +/** + * Tests for enum type as id. + * + * @author Hardy Ferentschik + */ +@TestForIssue(jiraKey = "ANN-744") +@DomainModel( + annotatedClasses = PlanetCheatSheet.class +) +@SessionFactory +public class EnumIdTest { + + @Test + public void testEnumAsId(SessionFactoryScope scope) { + PlanetCheatSheet mercury = new PlanetCheatSheet(); + scope.inTransaction( + session -> { + mercury.setPlanet( Planet.MERCURY ); + mercury.setMass( 3.303e+23 ); + mercury.setRadius( 2.4397e6 ); + mercury.setNumberOfInhabitants( 0 ); + session.persist( mercury ); + } + ); + + scope.inTransaction( + session -> { + PlanetCheatSheet mercuryFromDb = session.get( PlanetCheatSheet.class, mercury.getPlanet() ); + assertNotNull( mercuryFromDb ); + session.delete( mercuryFromDb ); + } + ); + + scope.inTransaction( + session -> { + PlanetCheatSheet mercuryFromDb = session.get( + PlanetCheatSheet.class, + Planet.MERCURY + ); + assertNull( mercuryFromDb ); + } + ); + + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdClassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdClassTest.java new file mode 100644 index 0000000000..78c12706d1 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdClassTest.java @@ -0,0 +1,47 @@ +/* + * 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.orm.test.annotations.id; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.entities.Location; +import org.hibernate.orm.test.annotations.id.entities.Tower; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + + +/** + * @author Emmanuel Bernard + */ +@DomainModel( + annotatedClasses = Tower.class +) +@SessionFactory +public class IdClassTest { + + @Test + public void testIdClassInSuperclass(SessionFactoryScope scope) { + Tower tower = new Tower(); + tower.latitude = 10.3; + tower.longitude = 45.4; + + scope.inTransaction( + session -> { + session.persist( tower ); + session.flush(); + session.clear(); + Location loc = new Location(); + loc.latitude = tower.latitude; + loc.longitude = tower.longitude; + assertNotNull( session.get( Tower.class, loc ) ); + } + ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdTest.java new file mode 100644 index 0000000000..96a75679f2 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/IdTest.java @@ -0,0 +1,353 @@ +/* + * 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.orm.test.annotations.id; + +import org.hibernate.mapping.Column; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.entities.Ball; +import org.hibernate.orm.test.annotations.id.entities.BreakDance; +import org.hibernate.orm.test.annotations.id.entities.Computer; +import org.hibernate.orm.test.annotations.id.entities.Department; +import org.hibernate.orm.test.annotations.id.entities.Dog; +import org.hibernate.orm.test.annotations.id.entities.FirTree; +import org.hibernate.orm.test.annotations.id.entities.Footballer; +import org.hibernate.orm.test.annotations.id.entities.FootballerPk; +import org.hibernate.orm.test.annotations.id.entities.Furniture; +import org.hibernate.orm.test.annotations.id.entities.GoalKeeper; +import org.hibernate.orm.test.annotations.id.entities.Home; +import org.hibernate.orm.test.annotations.id.entities.Hotel; +import org.hibernate.orm.test.annotations.id.entities.Monkey; +import org.hibernate.orm.test.annotations.id.entities.Phone; +import org.hibernate.orm.test.annotations.id.entities.Shoe; +import org.hibernate.orm.test.annotations.id.entities.SoundSystem; +import org.hibernate.orm.test.annotations.id.entities.Store; +import org.hibernate.orm.test.annotations.id.entities.Tree; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * @author Emmanuel Bernard + */ +@DomainModel( + annotatedClasses = { + Ball.class, Shoe.class, Store.class, + Department.class, Dog.class, Computer.class, Home.class, + Phone.class, Tree.class, FirTree.class, Footballer.class, + SoundSystem.class, Furniture.class, GoalKeeper.class, + BreakDance.class, Monkey.class, Hotel.class + }, + annotatedPackageNames = { + "org.hibernate.orm.test.annotations", + "org.hibernate.orm.test.annotations.id" + }, + xmlMappings = "org/hibernate/test/annotations/orm.xml" +) +@SessionFactory +public class IdTest { + + @Test + public void testNoGenerator(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Hotel hotel = new Hotel(); + hotel.setId( 12L ); + hotel.setName( "California" ); + session.saveOrUpdate( hotel ); + } + ); + + Hotel savedHotel = scope.fromTransaction( + session -> { + Hotel hotel = session.get( Hotel.class, 12L ); + assertNotNull( hotel ); + assertEquals( "California", hotel.getName() ); + assertNull( session.get( Hotel.class, 13L ) ); + return hotel; + } + ); + + //savedHotel is now detached + + scope.inTransaction( + session -> { + savedHotel.setName( "Hotel du nord" ); + session.saveOrUpdate( savedHotel ); + } + ); + + scope.inTransaction( + session -> { + Hotel hotel = session.get( Hotel.class, 12L ); + assertNotNull( hotel ); + assertEquals( "Hotel du nord", hotel.getName() ); + session.delete( hotel ); + } + ); + } + + @Test + public void testGenericGenerator(SessionFactoryScope scope) { + SoundSystem system = new SoundSystem(); + Furniture fur = new Furniture(); + scope.inTransaction( + session -> { + system.setBrand( "Genelec" ); + system.setModel( "T234" ); + session.persist( system ); + session.persist( fur ); + } + ); + + scope.inTransaction( + session -> { + SoundSystem systemFromDb = session.get( SoundSystem.class, system.getId() ); + Furniture furFromDb = session.get( Furniture.class, fur.getId() ); + assertNotNull( systemFromDb ); + assertNotNull( furFromDb ); + session.delete( systemFromDb ); + session.delete( furFromDb ); + } + ); + } + + /* + * Ensures that GenericGenerator annotations wrapped inside a + * GenericGenerators holder are bound correctly + */ + @Test + public void testGenericGenerators(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Monkey monkey = new Monkey(); + session.persist( monkey ); + session.flush(); + assertNotNull( monkey.getId() ); + session.delete( monkey ); + } + ); + } + + @Test + public void testTableGenerator(SessionFactoryScope scope) { + + Ball b = new Ball(); + Dog d = new Dog(); + Computer c = new Computer(); + scope.inTransaction( + session -> { + session.persist( b ); + session.persist( d ); + session.persist( c ); + } + ); + + assertEquals( new Integer( 1 ), b.getId(), "table id not generated" ); + assertEquals( new Integer( 1 ), d.getId(), "generator should not be shared" ); + assertEquals( new Long( 1 ), c.getId(), "default value should work" ); + + scope.inTransaction( + session -> { + session.delete( session.get( Ball.class, 1 ) ); + session.delete( session.get( Dog.class, 1 ) ); + session.delete( session.get( Computer.class, 1L ) ); + } + ); + } + + @Test + public void testSequenceGenerator(SessionFactoryScope scope) { + Shoe b = new Shoe(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Shoe.class, b.getId() ) ) + ); + } + + @Test + public void testClassLevelGenerator(SessionFactoryScope scope) { + Store b = new Store(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Store.class, b.getId() ) ) + + ); + } + + @Test + public void testMethodLevelGenerator(SessionFactoryScope scope) { + Department b = new Department(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Department.class, b.getId() ) ) + ); + } + + @Test + public void testDefaultSequence(SessionFactoryScope scope) { + Home h = new Home(); + scope.inTransaction( + session -> + session.persist( h ) + ); + + assertNotNull( h.getId() ); + + scope.inTransaction( + session -> { + Home reloadedHome = session.get( Home.class, h.getId() ); + assertEquals( h.getId(), reloadedHome.getId() ); + session.delete( reloadedHome ); + } + ); + } + + @Test + public void testParameterizedAuto(SessionFactoryScope scope) { + Home h = new Home(); + scope.inTransaction( + session -> + session.persist( h ) + ); + + assertNotNull( h.getId() ); + + scope.inTransaction( + session -> { + Home reloadedHome = session.get( Home.class, h.getId() ); + assertEquals( h.getId(), reloadedHome.getId() ); + session.delete( reloadedHome ); + } + ); + } + + @Test + public void testIdInEmbeddableSuperclass(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + FirTree christmasTree = new FirTree(); + session.persist( christmasTree ); + session.getTransaction().commit(); + session.clear(); + session.beginTransaction(); + christmasTree = session.get( FirTree.class, christmasTree.getId() ); + assertNotNull( christmasTree ); + session.delete( christmasTree ); + } + ); + } + + @Test + public void testIdClass(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Footballer fb = new Footballer( "David", "Beckam", "Arsenal" ); + GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" ); + session.persist( fb ); + session.persist( keeper ); + session.getTransaction().commit(); + session.clear(); + + // lookup by id + session.beginTransaction(); + FootballerPk fpk = new FootballerPk( "David", "Beckam" ); + fb = session.get( Footballer.class, fpk ); + FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" ); + keeper = session.get( GoalKeeper.class, fpk2 ); + assertNotNull( fb ); + assertNotNull( keeper ); + assertEquals( "Beckam", fb.getLastname() ); + assertEquals( "Arsenal", fb.getClub() ); + assertEquals( 1, session.createQuery( + "from Footballer f where f.firstname = 'David'" ).list().size() ); + session.getTransaction().commit(); + + // reattach by merge + session.beginTransaction(); + fb.setClub( "Bimbo FC" ); + session.merge( fb ); + session.getTransaction().commit(); + + // reattach by saveOrUpdate + session.beginTransaction(); + fb.setClub( "Bimbo FC SA" ); + session.saveOrUpdate( fb ); + session.getTransaction().commit(); + + // clean up + session.clear(); + session.beginTransaction(); + fpk = new FootballerPk( "David", "Beckam" ); + fb = session.get( Footballer.class, fpk ); + assertEquals( "Bimbo FC SA", fb.getClub() ); + session.delete( fb ); + session.delete( keeper ); + } + ); + } + + @Test + public void testColumnDefinition(SessionFactoryScope scope) { + Column idCol = (Column) scope.getMetadataImplementor().getEntityBinding( Ball.class.getName() ) + .getIdentifierProperty() + .getValue() + .getColumnIterator() + .next(); + assertEquals( "ball_id", idCol.getName() ); + } + + @Test + public void testLowAllocationSize(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + int size = 4; + BreakDance[] bds = new BreakDance[size]; + for ( int i = 0; i < size; i++ ) { + bds[i] = new BreakDance(); + session.persist( bds[i] ); + } + session.flush(); + for ( int i = 0; i < size; i++ ) { + assertEquals( i + 1, bds[i].id.intValue() ); + } + } + ); + scope.inTransaction( + session -> + session.createQuery( "delete from BreakDance" ).executeUpdate() + ); + + } + + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/JoinColumnOverrideTest.java similarity index 71% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/JoinColumnOverrideTest.java index 10a742255b..b95deeeb29 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/JoinColumnOverrideTest.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.annotations.id; +package org.hibernate.orm.test.annotations.id; import java.util.List; @@ -16,15 +16,13 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.annotations.id.entities.Bunny; -import org.hibernate.test.annotations.id.entities.PointyTooth; -import org.hibernate.test.annotations.id.entities.TwinkleToes; -import org.junit.Test; +import org.hibernate.testing.junit5.BaseUnitTest; +import org.hibernate.orm.test.annotations.id.entities.Bunny; +import org.hibernate.orm.test.annotations.id.entities.PointyTooth; +import org.hibernate.orm.test.annotations.id.entities.TwinkleToes; +import org.junit.jupiter.api.Test; -import org.jboss.logging.Logger; - -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests for JIRA issue ANN-748. @@ -32,7 +30,7 @@ import static org.junit.Assert.assertTrue; * @author Hardy Ferentschik */ @SuppressWarnings("unchecked") -public class JoinColumnOverrideTest extends BaseUnitTestCase { +public class JoinColumnOverrideTest extends BaseUnitTest { private static final String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " + "bunny_id numeric(128,0), primary key (id))"; @@ -40,8 +38,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { "bunny_id numeric(128,0), primary key (id))"; @Test - @TestForIssue( jiraKey = "ANN-748" ) - public void testBlownPrecision() throws Exception { + @TestForIssue(jiraKey = "ANN-748") + public void testBlownPrecision() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.DIALECT, "SQLServer" ) .build(); @@ -58,7 +56,6 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { List commands = new SchemaCreatorImpl( ssr ).generateCreationCommands( metadata, false ); for ( String command : commands ) { - log.debug( command ); if ( expectedSqlPointyTooth.equals( command ) ) { foundPointyToothCreate = true; @@ -68,8 +65,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { } } - assertTrue( "Expected create table command for PointyTooth entity not found", foundPointyToothCreate ); - assertTrue( "Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate ); + assertTrue( foundPointyToothCreate, "Expected create table command for PointyTooth entity not found" ); + assertTrue( foundTwinkleToesCreate, "Expected create table command for TwinkleToes entity not found" ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/UUIDGenerator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/UUIDGenerator.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.java index ca37e3f058..b56a7db47b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/UUIDGenerator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/UUIDGenerator.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.annotations.id; +package org.hibernate.orm.test.annotations.id; import java.math.BigInteger; import java.util.UUID; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Ball.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Ball.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Ball.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Ball.java index 235f58358c..85f43dc489 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Ball.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Ball.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/BreakDance.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/BreakDance.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/BreakDance.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/BreakDance.java index 2b9ef37c03..ae859ed02b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/BreakDance.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/BreakDance.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Bunny.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Bunny.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Bunny.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Bunny.java index 47ce4d9346..b4b8fa89dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Bunny.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Bunny.java @@ -6,10 +6,9 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -32,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class Bunny implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Computer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Computer.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Computer.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Computer.java index 31cf4f5577..7e38bf25bb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Computer.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Computer.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Department.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Department.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Department.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Department.java index e225bd1efd..d475907b40 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Department.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Department.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Dog.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Dog.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Dog.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Dog.java index 28aae83dfe..4f63aa3bbf 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Dog.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Dog.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FirTree.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FirTree.java similarity index 86% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FirTree.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FirTree.java index f42798ef62..c8630a5a01 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FirTree.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FirTree.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Footballer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Footballer.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Footballer.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Footballer.java index bb6f561d66..08260dc74f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Footballer.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Footballer.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.DiscriminatorColumn; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FootballerPk.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FootballerPk.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FootballerPk.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FootballerPk.java index ec413f7eeb..03ce38ad42 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/FootballerPk.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/FootballerPk.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Furniture.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Furniture.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Furniture.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Furniture.java index 3c4817c5f3..aaa26d3ef6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Furniture.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Furniture.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/GoalKeeper.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/GoalKeeper.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/GoalKeeper.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/GoalKeeper.java index 3fa4c9fa4d..9120f0936e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/GoalKeeper.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/GoalKeeper.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Home.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Home.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Home.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Home.java index 215a803e22..5435912e01 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Home.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Home.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Hotel.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Hotel.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Hotel.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Hotel.java index e8a4ead97b..50a98bbf44 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Hotel.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Hotel.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.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Location.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Location.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java index 18b22dab5b..868349cbfd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Location.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Location.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/MilitaryBuilding.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/MilitaryBuilding.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/MilitaryBuilding.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/MilitaryBuilding.java index 28b45bec1e..1ab537cef5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/MilitaryBuilding.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/MilitaryBuilding.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Monkey.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Monkey.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Monkey.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Monkey.java index f36f7b2545..8b91181410 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Monkey.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Monkey.java @@ -6,7 +6,7 @@ */ //$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Phone.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Phone.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Phone.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Phone.java index 50566038d4..a5949d4314 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Phone.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Phone.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Planet.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Planet.java similarity index 85% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Planet.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Planet.java index 79183c18aa..ce50b86947 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Planet.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Planet.java @@ -6,7 +6,7 @@ */ // $Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; public enum Planet { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PlanetCheatSheet.java similarity index 97% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PlanetCheatSheet.java index 6d5672f351..7ee10debd7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PlanetCheatSheet.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.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PointyTooth.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PointyTooth.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PointyTooth.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PointyTooth.java index 3f3cb8a18e..89dd32c207 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/PointyTooth.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/PointyTooth.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import java.math.BigDecimal; import javax.persistence.Column; @@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class PointyTooth implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Shoe.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Shoe.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Shoe.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Shoe.java index 5d8a1dcee3..4c1c3dba23 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Shoe.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Shoe.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/SoundSystem.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/SoundSystem.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/SoundSystem.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/SoundSystem.java index 9a8a5ec62d..911964ff25 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/SoundSystem.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/SoundSystem.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Store.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Store.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Store.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Store.java index 93b0cd322b..306728c256 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Store.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Store.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tower.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tower.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tower.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tower.java index 2e26384f56..16305e25e1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tower.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tower.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tree.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tree.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tree.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tree.java index 327f8281ef..d90bea501c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/Tree.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/Tree.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/TwinkleToes.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/TwinkleToes.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/TwinkleToes.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/TwinkleToes.java index 4a1c4d8877..cdb4e63461 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/entities/TwinkleToes.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/entities/TwinkleToes.java @@ -6,10 +6,9 @@ */ //$Id$ -package org.hibernate.test.annotations.id.entities; +package org.hibernate.orm.test.annotations.id.entities; import java.io.Serializable; import java.math.BigDecimal; -import java.math.BigInteger; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -32,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class TwinkleToes implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/AutoEntity.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/AutoEntity.java index c400c07156..12074f8bfe 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/AutoEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/AutoEntity.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/CompleteSequenceEntity.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/CompleteSequenceEntity.java index 9f8d1aaa4b..da0d953d6c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/CompleteSequenceEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/CompleteSequenceEntity.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java index e79ff1bfd5..c9e71edbdd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity1.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity1.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import java.io.Serializable; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java index fc6a084ea4..71c6c888fd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/DedicatedSequenceEntity2.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/DedicatedSequenceEntity2.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import java.io.Serializable; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalSequenceEntity.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalSequenceEntity.java index 50f839e7e1..3c934ed23d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalSequenceEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalSequenceEntity.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalTableEntity.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalTableEntity.java index 57cee3f4e9..ec57fe9ef4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/MinimalTableEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/MinimalTableEntity.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.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java similarity index 70% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java index 9a778187a5..451695107d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/NewGeneratorMappingsTest.java @@ -4,11 +4,8 @@ * 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.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; -import org.junit.Test; - -import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.id.IdentifierGenerator; import org.hibernate.id.enhanced.NoopOptimizer; @@ -18,11 +15,15 @@ import org.hibernate.id.enhanced.TableGenerator; import org.hibernate.internal.util.StringHelper; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.ServiceRegistry; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test mapping the {@link javax.persistence.GenerationType GenerationTypes} to the corresponding @@ -31,38 +32,29 @@ import static org.junit.Assert.assertTrue; * @author Steve Ebersole * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ -public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { +@DomainModel( + annotatedClasses = { MinimalSequenceEntity.class, CompleteSequenceEntity.class, AutoEntity.class, MinimalTableEntity.class, DedicatedSequenceEntity1.class, DedicatedSequenceEntity2.class - }; - } + }, + annotatedPackageNames = { + "org.hibernate.orm.test.annotations.id.generationmappings" + } +) +@SessionFactory( + exportSchema = false +) +@ServiceRegistry(settings = @ServiceRegistry.Setting(name =Environment.HBM2DDL_AUTO, value = "")) +public class NewGeneratorMappingsTest { - @Override - protected String[] getAnnotatedPackages() { - return new String[] { this.getClass().getPackage().getName() }; - } - - @Override - protected void configure(Configuration cfg) { - super.configure( cfg ); - cfg.setProperty( Environment.HBM2DDL_AUTO, "" ); - } - - @Override - protected boolean createSchema() { - return false; - } @Test - public void testMinimalSequenceEntity() { - final EntityPersister persister = sessionFactory().getEntityPersister( MinimalSequenceEntity.class.getName() ); + public void testMinimalSequenceEntity(SessionFactoryScope scope) { + final EntityPersister persister = scope.getSessionFactory().getEntityPersister( MinimalSequenceEntity.class.getName() ); IdentifierGenerator generator = persister.getIdentifierGenerator(); assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; @@ -75,8 +67,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { } @Test - public void testCompleteSequenceEntity() { - final EntityPersister persister = sessionFactory().getEntityPersister( CompleteSequenceEntity.class.getName() ); + public void testCompleteSequenceEntity(SessionFactoryScope scope) { + final EntityPersister persister = scope.getSessionFactory().getEntityPersister( CompleteSequenceEntity.class.getName() ); IdentifierGenerator generator = persister.getIdentifierGenerator(); assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; @@ -86,8 +78,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { } @Test - public void testAutoEntity() { - final EntityPersister persister = sessionFactory().getEntityPersister( AutoEntity.class.getName() ); + public void testAutoEntity(SessionFactoryScope scope) { + final EntityPersister persister = scope.getSessionFactory().getEntityPersister( AutoEntity.class.getName() ); IdentifierGenerator generator = persister.getIdentifierGenerator(); assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; @@ -97,8 +89,8 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { } @Test - public void testMinimalTableEntity() { - final EntityPersister persister = sessionFactory().getEntityPersister( MinimalTableEntity.class.getName() ); + public void testMinimalTableEntity(SessionFactoryScope scope) { + final EntityPersister persister = scope.getSessionFactory().getEntityPersister( MinimalTableEntity.class.getName() ); IdentifierGenerator generator = persister.getIdentifierGenerator(); assertTrue( TableGenerator.class.isInstance( generator ) ); TableGenerator tabGenerator = (TableGenerator) generator; @@ -115,9 +107,9 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { @Test @TestForIssue(jiraKey = "HHH-6790") - public void testSequencePerEntity() { + public void testSequencePerEntity(SessionFactoryScope scope) { // Checking first entity. - EntityPersister persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() ); + EntityPersister persister = scope.getSessionFactory().getEntityPersister( DedicatedSequenceEntity1.class.getName() ); IdentifierGenerator generator = persister.getIdentifierGenerator(); assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; @@ -127,7 +119,7 @@ public class NewGeneratorMappingsTest extends BaseCoreFunctionalTestCase { ); // Checking second entity. - persister = sessionFactory().getEntityPersister( DedicatedSequenceEntity2.class.getName() ); + persister = scope.getSessionFactory().getEntityPersister( DedicatedSequenceEntity2.class.getName() ); generator = persister.getIdentifierGenerator(); assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); seqGenerator = (SequenceStyleGenerator) generator; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/package-info.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/package-info.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/package-info.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/package-info.java index ec3e1af3f1..5ef1006221 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/generationmappings/package-info.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/generationmappings/package-info.java @@ -12,7 +12,7 @@ } ) -package org.hibernate.test.annotations.id.generationmappings; +package org.hibernate.orm.test.annotations.id.generationmappings; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/package-info.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/package-info.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/package-info.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/package-info.java index 292023beb5..0f13f46c72 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/package-info.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/package-info.java @@ -14,6 +14,6 @@ @org.hibernate.annotations.GenericGenerators( @org.hibernate.annotations.GenericGenerator(name = "system-uuid-2", strategy = "uuid") ) -package org.hibernate.test.annotations.id; +package org.hibernate.orm.test.annotations.id; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/EnumIdTest.java new file mode 100644 index 0000000000..b5d65ae466 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/EnumIdTest.java @@ -0,0 +1,64 @@ +/* + * 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.orm.test.annotations.id.sequences; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.sequences.entities.Planet; +import org.hibernate.orm.test.annotations.id.sequences.entities.PlanetCheatSheet; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + +/** + * Tests for enum type as id. + * + * @author Hardy Ferentschik + */ +@TestForIssue(jiraKey = "ANN-744") +@DomainModel( + annotatedClasses = PlanetCheatSheet.class +) +@SessionFactory +public class EnumIdTest { + + @Test + public void testEnumAsId(SessionFactoryScope scope) { + PlanetCheatSheet mercury = new PlanetCheatSheet(); + scope.inTransaction( + session -> { + mercury.setPlanet( Planet.MERCURY ); + mercury.setMass( 3.303e+23 ); + mercury.setRadius( 2.4397e6 ); + mercury.setNumberOfInhabitants( 0 ); + session.persist( mercury ); + } + ); + + scope.inTransaction( + session -> { + PlanetCheatSheet mercuryFromDb = session.get( + PlanetCheatSheet.class, + mercury.getPlanet() + ); + assertNotNull( mercuryFromDb ); + session.delete( mercuryFromDb ); + } + ); + + scope.inTransaction( + session -> { + PlanetCheatSheet mercuryFromDb = session.get( PlanetCheatSheet.class, Planet.MERCURY ); + assertNull( mercuryFromDb ); + } + ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/HibernateSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/HibernateSequenceTest.java new file mode 100644 index 0000000000..9d69d569d0 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/HibernateSequenceTest.java @@ -0,0 +1,66 @@ +/* + * 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.orm.test.annotations.id.sequences; + + +import org.hibernate.dialect.H2Dialect; +import org.hibernate.id.IdentifierGenerator; +import org.hibernate.id.enhanced.SequenceStyleGenerator; +import org.hibernate.mapping.Table; +import org.hibernate.persister.entity.EntityPersister; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialect; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.sequences.entities.HibernateSequenceEntity; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@TestForIssue(jiraKey = "HHH-6068") +@RequiresDialect(value = H2Dialect.class) +@DomainModel( + annotatedClasses = HibernateSequenceEntity.class, + xmlMappings = "org/hibernate/orm/test/annotations/id/sequences/orm.xml" +) +@SessionFactory(createSecondarySchemas = true) +public class HibernateSequenceTest { + private static final String SCHEMA_NAME = "OTHER_SCHEMA"; + + @Test + public void testHibernateSequenceSchema(SessionFactoryScope scope) { + EntityPersister persister = scope.getSessionFactory() + .getEntityPersister( HibernateSequenceEntity.class.getName() ); + IdentifierGenerator generator = persister.getIdentifierGenerator(); + assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); + SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; + assertEquals( + Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ), + seqGenerator.getDatabaseStructure().getName() + ); + } + + @Test + public void testHibernateSequenceNextVal(SessionFactoryScope scope) { + HibernateSequenceEntity entity = new HibernateSequenceEntity(); + scope.inTransaction( + session -> { + entity.setText( "sample text" ); + session.save( entity ); + } + ); + + assertNotNull( entity.getId() ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdClassTest.java similarity index 84% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdClassTest.java index bb39013675..aeb4b9a95d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdClassTest.java @@ -4,13 +4,13 @@ * 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.id.sequences; +package org.hibernate.orm.test.annotations.id.sequences; import org.hibernate.testing.orm.junit.DomainModel; import org.hibernate.testing.orm.junit.SessionFactory; import org.hibernate.testing.orm.junit.SessionFactoryScope; -import org.hibernate.test.annotations.id.sequences.entities.Location; -import org.hibernate.test.annotations.id.sequences.entities.Tower; +import org.hibernate.orm.test.annotations.id.sequences.entities.Location; +import org.hibernate.orm.test.annotations.id.sequences.entities.Tower; import org.junit.jupiter.api.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdTest.java new file mode 100644 index 0000000000..6d92d9f702 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/IdTest.java @@ -0,0 +1,344 @@ +/* + * 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.orm.test.annotations.id.sequences; + +import org.hibernate.mapping.Column; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.hibernate.orm.test.annotations.id.generationmappings.DedicatedSequenceEntity1; +import org.hibernate.orm.test.annotations.id.generationmappings.DedicatedSequenceEntity2; +import org.hibernate.orm.test.annotations.id.sequences.entities.Ball; +import org.hibernate.orm.test.annotations.id.sequences.entities.BreakDance; +import org.hibernate.orm.test.annotations.id.sequences.entities.Computer; +import org.hibernate.orm.test.annotations.id.sequences.entities.Department; +import org.hibernate.orm.test.annotations.id.sequences.entities.Dog; +import org.hibernate.orm.test.annotations.id.sequences.entities.FirTree; +import org.hibernate.orm.test.annotations.id.sequences.entities.Footballer; +import org.hibernate.orm.test.annotations.id.sequences.entities.FootballerPk; +import org.hibernate.orm.test.annotations.id.sequences.entities.Furniture; +import org.hibernate.orm.test.annotations.id.sequences.entities.GoalKeeper; +import org.hibernate.orm.test.annotations.id.sequences.entities.Home; +import org.hibernate.orm.test.annotations.id.sequences.entities.Monkey; +import org.hibernate.orm.test.annotations.id.sequences.entities.Phone; +import org.hibernate.orm.test.annotations.id.sequences.entities.Shoe; +import org.hibernate.orm.test.annotations.id.sequences.entities.SoundSystem; +import org.hibernate.orm.test.annotations.id.sequences.entities.Store; +import org.hibernate.orm.test.annotations.id.sequences.entities.Tree; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +/** + * @author Emmanuel Bernard + * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) + */ +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsSequences.class) +@DomainModel( + annotatedClasses = { + Ball.class, Shoe.class, Store.class, + Department.class, Dog.class, Computer.class, Home.class, + Phone.class, Tree.class, FirTree.class, Footballer.class, + SoundSystem.class, Furniture.class, GoalKeeper.class, + BreakDance.class, Monkey.class, DedicatedSequenceEntity1.class, + DedicatedSequenceEntity2.class + }, + annotatedPackageNames = { + "org.hibernate.orm.test.annotations", + "org.hibernate.orm.test.annotations.id", + "org.hibernate.orm.test.annotations.id.generationmappings" + }, + xmlMappings = "org/hibernate/test/annotations/orm.xml" + +) +@SessionFactory +public class IdTest { + + @Test + public void testGenericGenerator(SessionFactoryScope scope) { + SoundSystem system = new SoundSystem(); + Furniture fur = new Furniture(); + scope.inTransaction( + session -> { + system.setBrand( "Genelec" ); + system.setModel( "T234" ); + session.persist( system ); + session.persist( fur ); + } + ); + + scope.inTransaction( + session -> { + SoundSystem systemfromDb = session.get( SoundSystem.class, system.getId() ); + Furniture furFromDb = session.get( Furniture.class, fur.getId() ); + assertNotNull( systemfromDb ); + assertNotNull( furFromDb ); + session.delete( systemfromDb ); + session.delete( furFromDb ); + } + ); + } + + @Test + public void testGenericGenerators(SessionFactoryScope scope) { + // Ensures that GenericGenerator annotations wrapped inside a GenericGenerators holder are bound correctly + scope.inTransaction( + session -> { + Monkey monkey = new Monkey(); + session.persist( monkey ); + session.flush(); + assertNotNull( monkey.getId() ); + } + ); + + scope.inTransaction( + session -> + session.createQuery( "delete from Monkey" ).executeUpdate() + ); + } + + @Test + public void testTableGenerator(SessionFactoryScope scope) { + Ball b = new Ball(); + Dog d = new Dog(); + Computer c = new Computer(); + scope.inTransaction( + session -> { + session.persist( b ); + session.persist( d ); + session.persist( c ); + } + ); + + assertEquals( new Integer( 1 ), b.getId(), "table id not generated" ); + assertEquals( new Integer( 1 ), d.getId(), "generator should not be shared" ); + assertEquals( new Long( 1 ), c.getId(), "default value should work" ); + + scope.inTransaction( + session -> { + session.delete( session.get( Ball.class, 1 ) ); + session.delete( session.get( Dog.class, 1 ) ); + session.delete( session.get( Computer.class, 1L ) ); + } + ); + } + + @Test + public void testSequenceGenerator(SessionFactoryScope scope) { + Shoe b = new Shoe(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Shoe.class, b.getId() ) ) + ); + } + + @Test + public void testClassLevelGenerator(SessionFactoryScope scope) { + Store b = new Store(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Store.class, b.getId() ) ) + ); + } + + @Test + public void testMethodLevelGenerator(SessionFactoryScope scope) { + Department b = new Department(); + scope.inTransaction( + session -> + session.persist( b ) + ); + + assertNotNull( b.getId() ); + + scope.inTransaction( + session -> + session.delete( session.get( Department.class, b.getId() ) ) + ); + } + + @Test + public void testDefaultSequence(SessionFactoryScope scope) { + Home h = new Home(); + scope.inTransaction( + session -> + session.persist( h ) + ); + + assertNotNull( h.getId() ); + + scope.inTransaction( + session -> { + Home reloadedHome = session.get( Home.class, h.getId() ); + assertEquals( h.getId(), reloadedHome.getId() ); + session.delete( reloadedHome ); + } + ); + } + + @Test + public void testParameterizedAuto(SessionFactoryScope scope) { + Home h = new Home(); + scope.inTransaction( + session -> + session.persist( h ) + ); + + assertNotNull( h.getId() ); + + scope.inTransaction( + session -> { + Home reloadedHome = session.get( Home.class, h.getId() ); + assertEquals( h.getId(), reloadedHome.getId() ); + session.delete( reloadedHome ); + } + ); + } + + @Test + public void testIdInEmbeddableSuperclass(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + FirTree christmasTree = new FirTree(); + session.persist( christmasTree ); + session.getTransaction().commit(); + session.clear(); + + session.beginTransaction(); + + christmasTree = session.get( FirTree.class, christmasTree.getId() ); + assertNotNull( christmasTree ); + session.delete( christmasTree ); + } + ); + } + + @Test + public void testIdClass(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + Footballer fb = new Footballer( "David", "Beckam", "Arsenal" ); + GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" ); + session.persist( fb ); + session.persist( keeper ); + session.getTransaction().commit(); + session.clear(); + + // lookup by id + session.beginTransaction(); + FootballerPk fpk = new FootballerPk( "David", "Beckam" ); + fb = session.get( Footballer.class, fpk ); + FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" ); + keeper = session.get( GoalKeeper.class, fpk2 ); + assertNotNull( fb ); + assertNotNull( keeper ); + assertEquals( "Beckam", fb.getLastname() ); + assertEquals( "Arsenal", fb.getClub() ); + assertEquals( + 1, + session.createQuery( "from Footballer f where f.firstname = 'David'" ) + .list().size() + ); + session.getTransaction().commit(); + + // reattach by merge + session.beginTransaction(); + fb.setClub( "Bimbo FC" ); + session.merge( fb ); + session.getTransaction().commit(); + + // reattach by saveOrUpdate + session.beginTransaction(); + fb.setClub( "Bimbo FC SA" ); + session.saveOrUpdate( fb ); + session.getTransaction().commit(); + + // clean up + session.clear(); + session.beginTransaction(); + fpk = new FootballerPk( "David", "Beckam" ); + fb = session.get( Footballer.class, fpk ); + assertEquals( "Bimbo FC SA", fb.getClub() ); + session.delete( fb ); + session.delete( keeper ); + } + ); + } + + @Test + @TestForIssue(jiraKey = "HHH-6790") + public void testSequencePerEntity(SessionFactoryScope scope) { + DedicatedSequenceEntity1 entity1 = new DedicatedSequenceEntity1(); + DedicatedSequenceEntity2 entity2 = new DedicatedSequenceEntity2(); + scope.inTransaction( + session -> { + session.persist( entity1 ); + session.persist( entity2 ); + } + ); + + assertEquals( 1, entity1.getId().intValue() ); + assertEquals( 1, entity2.getId().intValue() ); + + scope.inTransaction( + session -> { + session.createQuery( "delete from DedicatedSequenceEntity1" ).executeUpdate(); + session.createQuery( "delete from " + DedicatedSequenceEntity2.ENTITY_NAME ).executeUpdate(); + } + ); + } + + @Test + public void testColumnDefinition(SessionFactoryScope scope) { + Column idCol = (Column) scope.getMetadataImplementor().getEntityBinding( Ball.class.getName() ) + .getIdentifierProperty().getValue().getColumnIterator().next(); + assertEquals( "ball_id", idCol.getName() ); + } + + @Test + public void testLowAllocationSize(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + int size = 4; + BreakDance[] bds = new BreakDance[size]; + for ( int i = 0; i < size; i++ ) { + bds[i] = new BreakDance(); + session.persist( bds[i] ); + } + session.flush(); + for ( int i = 0; i < size; i++ ) { + assertEquals( i + 1, bds[i].id.intValue() ); + } + } + ); + scope.inTransaction( + session -> + session.createQuery( "delete from BreakDance" ).executeUpdate() + ); + } + + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/JoinColumnOverrideTest.java similarity index 69% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/JoinColumnOverrideTest.java index ce52e419c1..eef7e80df2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/JoinColumnOverrideTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/JoinColumnOverrideTest.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.test.annotations.id.sequences; +package org.hibernate.orm.test.annotations.id.sequences; import java.util.List; @@ -18,23 +18,21 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.hibernate.test.annotations.id.sequences.entities.Bunny; -import org.hibernate.test.annotations.id.sequences.entities.PointyTooth; -import org.hibernate.test.annotations.id.sequences.entities.TwinkleToes; -import org.junit.Test; +import org.hibernate.testing.junit5.BaseUnitTest; +import org.hibernate.orm.test.annotations.id.sequences.entities.Bunny; +import org.hibernate.orm.test.annotations.id.sequences.entities.PointyTooth; +import org.hibernate.orm.test.annotations.id.sequences.entities.TwinkleToes; +import org.junit.jupiter.api.Test; -import org.jboss.logging.Logger; +import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.Assert.assertTrue; /** * Tests for JIRA issue ANN-748. * * @author Hardy Ferentschik */ -@SuppressWarnings("unchecked") -public class JoinColumnOverrideTest extends BaseUnitTestCase { +public class JoinColumnOverrideTest extends BaseUnitTest { private static final String expectedSqlPointyTooth = "create table PointyTooth (id numeric(128,0) not null, " + "bunny_id numeric(128,0), primary key (id))"; @@ -42,8 +40,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { "bunny_id numeric(128,0), primary key (id))"; @Test - @TestForIssue( jiraKey = "ANN-748" ) - public void testBlownPrecision() throws Exception { + @TestForIssue(jiraKey = "ANN-748") + public void testBlownPrecision() { StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.DIALECT, "SQLServer" ) .build(); @@ -59,7 +57,6 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { List commands = new SchemaCreatorImpl( ssr ).generateCreationCommands( metadata, false ); for ( String command : commands ) { - log.debug( command ); if ( expectedSqlPointyTooth.equals( command ) ) { foundPointyToothCreate = true; @@ -69,8 +66,8 @@ public class JoinColumnOverrideTest extends BaseUnitTestCase { } } - assertTrue( "Expected create table command for PointyTooth entity not found", foundPointyToothCreate ); - assertTrue( "Expected create table command for TwinkleToes entity not found", foundTwinkleToesCreate ); + assertTrue( foundPointyToothCreate, "Expected create table command for PointyTooth entity not found" ); + assertTrue( foundTwinkleToesCreate, "Expected create table command for TwinkleToes entity not found" ); } finally { StandardServiceRegistryBuilder.destroy( ssr ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/UUIDGenerator.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/UUIDGenerator.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.java index e75f1ac80b..aebfbdf90e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/UUIDGenerator.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/UUIDGenerator.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.annotations.id.sequences; +package org.hibernate.orm.test.annotations.id.sequences; import java.math.BigInteger; import java.util.UUID; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Ball.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Ball.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Ball.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Ball.java index 53914157d3..5726bdcbc8 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Ball.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Ball.java @@ -6,7 +6,7 @@ */ //$Id: Ball.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/BreakDance.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/BreakDance.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/BreakDance.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/BreakDance.java index fd5081656f..512449ad0c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/BreakDance.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/BreakDance.java @@ -6,7 +6,7 @@ */ //$Id: BreakDance.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Bunny.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Bunny.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Bunny.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Bunny.java index 6bcdc32f70..862e6e42a5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Bunny.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Bunny.java @@ -6,7 +6,7 @@ */ //$Id: Bunny.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import java.math.BigDecimal; import java.util.Set; @@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class Bunny implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Computer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Computer.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Computer.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Computer.java index 0f9f5c1cfd..58a5ddd786 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Computer.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Computer.java @@ -6,7 +6,7 @@ */ //$Id: Computer.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Department.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Department.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Department.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Department.java index 04447e1405..8ce52305b4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Department.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Department.java @@ -6,7 +6,7 @@ */ //$Id: Department.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Dog.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Dog.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Dog.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Dog.java index b87c392eb7..23839ffd62 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Dog.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Dog.java @@ -6,7 +6,7 @@ */ //$Id: Dog.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FirTree.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FirTree.java similarity index 86% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FirTree.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FirTree.java index 1079d3e6ad..67c2dc5a6b 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FirTree.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FirTree.java @@ -6,7 +6,7 @@ */ //$Id: FirTree.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Footballer.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Footballer.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Footballer.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Footballer.java index 3c86ba688d..0c44a7ae6d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Footballer.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Footballer.java @@ -6,7 +6,7 @@ */ //$Id: Footballer.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.DiscriminatorColumn; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FootballerPk.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FootballerPk.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FootballerPk.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FootballerPk.java index 0cd2ae023f..8b6d6ede50 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/FootballerPk.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/FootballerPk.java @@ -6,7 +6,7 @@ */ //$Id: FootballerPk.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Furniture.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Furniture.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Furniture.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Furniture.java index 26d9c36608..6a75113a23 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Furniture.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Furniture.java @@ -6,7 +6,7 @@ */ //$Id: Furniture.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/GoalKeeper.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/GoalKeeper.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/GoalKeeper.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/GoalKeeper.java index 58bcb8c2d7..3bcf6f0646 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/GoalKeeper.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/GoalKeeper.java @@ -6,7 +6,7 @@ */ //$Id: GoalKeeper.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/HibernateSequenceEntity.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/HibernateSequenceEntity.java index e1e487da61..a59fa5d483 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/HibernateSequenceEntity.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/HibernateSequenceEntity.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.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Home.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Home.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Home.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Home.java index 98afffeadb..556d1c71f9 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Home.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Home.java @@ -6,7 +6,7 @@ */ //$Id: Home.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Location.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Location.java similarity index 94% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Location.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Location.java index 7286f4b56e..fe195fb0db 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Location.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Location.java @@ -6,7 +6,7 @@ */ //$Id: Location.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/MilitaryBuilding.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/MilitaryBuilding.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/MilitaryBuilding.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/MilitaryBuilding.java index 5905ca5439..ea3bede791 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/MilitaryBuilding.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/MilitaryBuilding.java @@ -6,7 +6,7 @@ */ //$Id: MilitaryBuilding.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Monkey.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Monkey.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Monkey.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Monkey.java index e8ad18a0c1..3868cdd5ac 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Monkey.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Monkey.java @@ -6,7 +6,7 @@ */ //$ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Phone.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Phone.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Phone.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Phone.java index b0a8df46e6..cda86fc450 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Phone.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Phone.java @@ -6,7 +6,7 @@ */ //$Id: Phone.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Planet.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Planet.java similarity index 85% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Planet.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Planet.java index 80943e8726..fd027a75eb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Planet.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Planet.java @@ -6,7 +6,7 @@ */ // $Id: Planet.java 14785 2008-06-19 10:44:33Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; public enum Planet { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PlanetCheatSheet.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PlanetCheatSheet.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PlanetCheatSheet.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PlanetCheatSheet.java index 490b1a8073..f5006a7f2c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PlanetCheatSheet.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PlanetCheatSheet.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.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PointyTooth.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PointyTooth.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PointyTooth.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PointyTooth.java index fd7d85b068..705ef77709 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/PointyTooth.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/PointyTooth.java @@ -6,7 +6,7 @@ */ //$Id: PointyTooth.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import java.math.BigDecimal; import javax.persistence.Column; @@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class PointyTooth implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Shoe.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Shoe.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Shoe.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Shoe.java index 67a43f4652..0c38b1fffb 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Shoe.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Shoe.java @@ -6,7 +6,7 @@ */ //$Id: Shoe.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/SoundSystem.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/SoundSystem.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/SoundSystem.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/SoundSystem.java index 2c5b5befc9..0f442b9ace 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/SoundSystem.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/SoundSystem.java @@ -6,7 +6,7 @@ */ //$Id: SoundSystem.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Store.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Store.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Store.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Store.java index 5aaa3e70de..d72ea3ba41 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Store.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Store.java @@ -6,7 +6,7 @@ */ //$Id: Store.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tower.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tower.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tower.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tower.java index e99e1e2656..81b675c66e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tower.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tower.java @@ -6,7 +6,7 @@ */ //$Id: Tower.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.AttributeOverride; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tree.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tree.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tree.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tree.java index b8163780df..b68932ddaf 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/Tree.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/Tree.java @@ -6,7 +6,7 @@ */ //$Id: Tree.java 14760 2008-06-11 07:33:15Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/TwinkleToes.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/TwinkleToes.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/TwinkleToes.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/TwinkleToes.java index e0b7f80ccf..91ed463114 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/entities/TwinkleToes.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/entities/TwinkleToes.java @@ -6,7 +6,7 @@ */ //$Id: TwinkleToes.java 14761 2008-06-11 13:51:06Z hardy.ferentschik $ -package org.hibernate.test.annotations.id.sequences.entities; +package org.hibernate.orm.test.annotations.id.sequences.entities; import java.io.Serializable; import java.math.BigDecimal; import javax.persistence.Column; @@ -31,7 +31,7 @@ import org.hibernate.annotations.GenericGenerator; public class TwinkleToes implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "java5_uuid") - @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.test.annotations.id.UUIDGenerator") + @GenericGenerator(name = "java5_uuid", strategy = "org.hibernate.orm.test.annotations.id.UUIDGenerator") @Column(name = "id", precision = 128, scale = 0) private BigDecimal id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/package-info.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/package-info.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/package-info.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/package-info.java index 5883beaa2a..12ef39dcb2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/package-info.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/id/sequences/package-info.java @@ -14,6 +14,6 @@ @org.hibernate.annotations.GenericGenerators( @org.hibernate.annotations.GenericGenerator(name = "system-uuid-2", strategy = "uuid") ) -package org.hibernate.test.annotations.id.sequences; +package org.hibernate.orm.test.annotations.id.sequences; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdmin.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdmin.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdmin.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdmin.java index 726b6ef29b..20899f98e5 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdmin.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdmin.java @@ -7,7 +7,7 @@ // $Id$ -package org.hibernate.test.annotations.idclass; +package org.hibernate.orm.test.annotations.idclass; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; @@ -27,7 +27,7 @@ import javax.persistence.Table; @IdClass(DomainAdminId.class) @NamedNativeQuery(name = "DomainAdmin.testQuery", query = "select * from domainadmin da where da.domain_name = 'org'", - resultClass = org.hibernate.test.annotations.idclass.DomainAdmin.class) + resultClass = org.hibernate.orm.test.annotations.idclass.DomainAdmin.class) public class DomainAdmin implements Serializable { @Id diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdminId.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdminId.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdminId.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdminId.java index 442cdb172e..28676fee90 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/DomainAdminId.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/DomainAdminId.java @@ -7,7 +7,7 @@ // $Id$ -package org.hibernate.test.annotations.idclass; +package org.hibernate.orm.test.annotations.idclass; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassCompositePKTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassCompositePKTest.java new file mode 100644 index 0000000000..4c3f6e7ec7 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassCompositePKTest.java @@ -0,0 +1,45 @@ +/* + * 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 . + */ + +// $Id$ + +package org.hibernate.orm.test.annotations.idclass; + + +import org.hibernate.query.Query; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + + +/** + * @author Stale W. Pedersen + */ +@DomainModel(annotatedClasses = DomainAdmin.class) +@SessionFactory +public class IdClassCompositePKTest { + + @Test + public void testEntityMappningPropertiesAreNotIgnored(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + DomainAdmin da = new DomainAdmin(); + da.setAdminUser( "admin" ); + da.setDomainName( "org" ); + + session.persist( da ); + Query q = session.getNamedQuery( "DomainAdmin.testQuery" ); + assertEquals( 1, q.list().size() ); + } + ); + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassMappedSuperclassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassMappedSuperclassTest.java similarity index 57% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassMappedSuperclassTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassMappedSuperclassTest.java index d39320f968..8e06388f4e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassMappedSuperclassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/IdClassMappedSuperclassTest.java @@ -4,67 +4,58 @@ * 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.idclass; +package org.hibernate.orm.test.annotations.idclass; import java.io.Serializable; - import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.IdClass; import javax.persistence.MappedSuperclass; -import org.hibernate.Session; -import org.junit.Test; - import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; /** * @author Chris Cranford */ @TestForIssue(jiraKey = "HHH-9114") -public class IdClassMappedSuperclassTest extends BaseCoreFunctionalTestCase { - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Simple.class }; - } +@DomainModel(annotatedClasses = IdClassMappedSuperclassTest.Simple.class) +@SessionFactory +public class IdClassMappedSuperclassTest { @Test - public void testIdClassWithMappedSuperclassAndId() throws Exception { - Session session = openSession(); - try { - // Persist the entity - Simple simple = new Simple(); - simple.setSimpleId( "1" ); - simple.setCategoryId( "2" ); - session.getTransaction().begin(); - session.save( simple ); - session.getTransaction().commit(); - session.clear(); + public void testIdClassWithMappedSuperclassAndId(SessionFactoryScope scope) { + Simple sim = scope.fromTransaction( + session -> { + // Persist the entity + Simple simple = new Simple(); + simple.setSimpleId( "1" ); + simple.setCategoryId( "2" ); + session.save( simple ); - // Query the entity. - session.getTransaction().begin(); - simple = session.createQuery( "FROM Simple", Simple.class ).getSingleResult(); - session.getTransaction().commit(); + session.getTransaction().commit(); - // tests. - assertNotNull( simple ); - assertEquals( "1", simple.getSimpleId() ); - assertEquals( "2", simple.getCategoryId() ); + session.clear(); + + session.getTransaction().begin(); + + // Query the entity. + simple = session.createQuery( "FROM Simple", Simple.class ).getSingleResult(); + return simple; + } + ); + + assertNotNull( sim ); + assertEquals( "1", sim.getSimpleId() ); + assertEquals( "2", sim.getCategoryId() ); - } - catch ( Throwable t ) { - if ( session.getTransaction().isActive() ) { - session.getTransaction().rollback(); - } - throw t; - } - finally { - session.close(); - } } @MappedSuperclass @@ -136,10 +127,14 @@ public class IdClassMappedSuperclassTest extends BaseCoreFunctionalTestCase { SimpleId simpleId1 = (SimpleId) o; - if ( getSimpleId() != null ? !getSimpleId().equals( simpleId1.getSimpleId() ) : simpleId1.getSimpleId() != null ) { + if ( getSimpleId() != null ? + !getSimpleId().equals( simpleId1.getSimpleId() ) : + simpleId1.getSimpleId() != null ) { return false; } - return getCategoryId() != null ? getCategoryId().equals( simpleId1.getCategoryId() ) : simpleId1.getCategoryId() == null; + return getCategoryId() != null ? + getCategoryId().equals( simpleId1.getCategoryId() ) : + simpleId1.getCategoryId() == null; } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.java similarity index 98% rename from hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.java index 016cc6cbca..15cd7d3082 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.java @@ -7,7 +7,7 @@ // $Id: $ -package org.hibernate.test.annotations.idclass.xml; +package org.hibernate.orm.test.annotations.idclass.xml; import java.io.Serializable; /** diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/IdClassXmlTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/IdClassXmlTest.java new file mode 100644 index 0000000000..3a0a365c15 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/annotations/idclass/xml/IdClassXmlTest.java @@ -0,0 +1,46 @@ +/* + * 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.orm.test.annotations.idclass.xml; + + +import org.hibernate.query.Query; + +import org.hibernate.testing.orm.junit.DomainModel; +import org.hibernate.testing.orm.junit.FailureExpected; +import org.hibernate.testing.orm.junit.SessionFactory; +import org.hibernate.testing.orm.junit.SessionFactoryScope; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * A test for HHH-4282 + * + * @author Hardy Ferentschik + */ +@FailureExpected( jiraKey = "HHH-4282" ) +@DomainModel( + annotatedClasses = HabitatSpeciesLink.class, + xmlMappings = "org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.xml" +) +@SessionFactory +public class IdClassXmlTest { + @Test + public void testEntityMappingPropertiesAreNotIgnored(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + HabitatSpeciesLink link = new HabitatSpeciesLink(); + link.setHabitatId( 1l ); + link.setSpeciesId( 1l ); + session.persist( link ); + + Query q = session.getNamedQuery( "testQuery" ); + assertEquals( 1, q.list().size() ); + } + ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java deleted file mode 100644 index f32cf527fa..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/EnumIdTest.java +++ /dev/null @@ -1,66 +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.id; - -import org.hibernate.Session; -import org.hibernate.Transaction; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.test.annotations.id.entities.Planet; -import org.hibernate.test.annotations.id.entities.PlanetCheatSheet; -import org.junit.Test; - -import org.jboss.logging.Logger; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -/** - * Tests for enum type as id. - * - * @author Hardy Ferentschik - */ -@SuppressWarnings("unchecked") -@TestForIssue( jiraKey = "ANN-744" ) -public class EnumIdTest extends BaseCoreFunctionalTestCase { - - @Test - public void testEnumAsId() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - PlanetCheatSheet mercury = new PlanetCheatSheet(); - mercury.setPlanet(Planet.MERCURY); - mercury.setMass(3.303e+23); - mercury.setRadius(2.4397e6); - mercury.setNumberOfInhabitants(0); - s.persist(mercury); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet()); - assertNotNull(mercuryFromDb); - log.debug(mercuryFromDb.toString()); - s.delete(mercuryFromDb); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY); - assertNull(mercury); - tx.commit(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { PlanetCheatSheet.class }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java deleted file mode 100644 index 676dbef156..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdClassTest.java +++ /dev/null @@ -1,48 +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.id; - -import org.junit.Test; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.test.annotations.id.entities.Location; -import org.hibernate.test.annotations.id.entities.Tower; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertNotNull; - -/** - * @author Emmanuel Bernard - */ -@SuppressWarnings("unchecked") -public class IdClassTest extends BaseCoreFunctionalTestCase { - @Test - public void testIdClassInSuperclass() throws Exception { - Tower tower = new Tower(); - tower.latitude = 10.3; - tower.longitude = 45.4; - Session s = openSession(); - Transaction tx = s.beginTransaction(); - s.persist( tower ); - s.flush(); - s.clear(); - Location loc = new Location(); - loc.latitude = tower.latitude; - loc.longitude = tower.longitude; - assertNotNull( s.get( Tower.class, loc ) ); - tx.rollback(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[]{ - Tower.class - }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java deleted file mode 100644 index 54df8342db..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/IdTest.java +++ /dev/null @@ -1,360 +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.id; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.mapping.Column; - -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.test.annotations.id.entities.Ball; -import org.hibernate.test.annotations.id.entities.BreakDance; -import org.hibernate.test.annotations.id.entities.Computer; -import org.hibernate.test.annotations.id.entities.Department; -import org.hibernate.test.annotations.id.entities.Dog; -import org.hibernate.test.annotations.id.entities.FirTree; -import org.hibernate.test.annotations.id.entities.Footballer; -import org.hibernate.test.annotations.id.entities.FootballerPk; -import org.hibernate.test.annotations.id.entities.Furniture; -import org.hibernate.test.annotations.id.entities.GoalKeeper; -import org.hibernate.test.annotations.id.entities.Home; -import org.hibernate.test.annotations.id.entities.Hotel; -import org.hibernate.test.annotations.id.entities.Monkey; -import org.hibernate.test.annotations.id.entities.Phone; -import org.hibernate.test.annotations.id.entities.Shoe; -import org.hibernate.test.annotations.id.entities.SoundSystem; -import org.hibernate.test.annotations.id.entities.Store; -import org.hibernate.test.annotations.id.entities.Tree; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -/** - * @author Emmanuel Bernard - */ -@SuppressWarnings("unchecked") -public class IdTest extends BaseNonConfigCoreFunctionalTestCase { - - @Test - public void testNoGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Hotel hotel = new Hotel(); - hotel.setId( 12l ); - hotel.setName("California"); - s.saveOrUpdate(hotel); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - hotel = (Hotel) s.get(Hotel.class, 12l); - assertNotNull(hotel); - assertEquals("California", hotel.getName()); - assertNull(s.get(Hotel.class, 13l)); - tx.commit(); - - s = openSession(); - tx = s.beginTransaction(); - //hotel is now detached - hotel.setName("Hotel du nord"); - s.saveOrUpdate(hotel); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - hotel = (Hotel) s.get(Hotel.class, 12l); - assertNotNull(hotel); - assertEquals("Hotel du nord", hotel.getName()); - s.delete(hotel); - tx.commit(); - s.close(); - } - - @Test - public void testGenericGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - SoundSystem system = new SoundSystem(); - system.setBrand("Genelec"); - system.setModel("T234"); - Furniture fur = new Furniture(); - s.persist(system); - s.persist(fur); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - system = (SoundSystem) s.get(SoundSystem.class, system.getId()); - fur = (Furniture) s.get(Furniture.class, fur.getId()); - assertNotNull(system); - assertNotNull(fur); - s.delete(system); - s.delete(fur); - tx.commit(); - s.close(); - } - - /* - * Ensures that GenericGenerator annotations wrapped inside a - * GenericGenerators holder are bound correctly - */ - @Test - public void testGenericGenerators() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Monkey monkey = new Monkey(); - s.persist(monkey); - s.flush(); - assertNotNull(monkey.getId()); - tx.rollback(); - s.close(); - } - - @Test - public void testTableGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - - Ball b = new Ball(); - Dog d = new Dog(); - Computer c = new Computer(); - s.persist( b ); - s.persist( d ); - s.persist(c); - tx.commit(); - s.close(); - assertEquals("table id not generated", new Integer(1), b.getId()); - assertEquals("generator should not be shared", new Integer(1), d - .getId()); - assertEquals("default value should work", new Long(1), c.getId()); - - s = openSession(); - tx = s.beginTransaction(); - s.delete(s.get(Ball.class, new Integer(1))); - s.delete(s.get(Dog.class, new Integer(1))); - s.delete(s.get(Computer.class, new Long(1))); - tx.commit(); - s.close(); - } - - @Test - public void testSequenceGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Shoe b = new Shoe(); - s.persist(b); - tx.commit(); - s.close(); - assertNotNull(b.getId()); - - s = openSession(); - tx = s.beginTransaction(); - s.delete(s.get(Shoe.class, b.getId())); - tx.commit(); - s.close(); - } - - @Test - public void testClassLevelGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Store b = new Store(); - s.persist(b); - tx.commit(); - s.close(); - assertNotNull(b.getId()); - - s = openSession(); - tx = s.beginTransaction(); - s.delete(s.get(Store.class, b.getId())); - tx.commit(); - s.close(); - } - - @Test - public void testMethodLevelGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Department b = new Department(); - s.persist(b); - tx.commit(); - s.close(); - assertNotNull( b.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - s.delete(s.get(Department.class, b.getId())); - tx.commit(); - s.close(); - } - - @Test - public void testDefaultSequence() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Home h = new Home(); - s.persist(h); - tx.commit(); - s.close(); - assertNotNull(h.getId()); - - s = openSession(); - tx = s.beginTransaction(); - Home reloadedHome = (Home) s.get(Home.class, h.getId()); - assertEquals(h.getId(), reloadedHome.getId()); - s.delete(reloadedHome); - tx.commit(); - s.close(); - } - - @Test - public void testParameterizedAuto() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Home h = new Home(); - s.persist(h); - tx.commit(); - s.close(); - assertNotNull(h.getId()); - - s = openSession(); - tx = s.beginTransaction(); - Home reloadedHome = (Home) s.get(Home.class, h.getId()); - assertEquals( h.getId(), reloadedHome.getId() ); - s.delete(reloadedHome); - tx.commit(); - s.close(); - } - - @Test - public void testIdInEmbeddableSuperclass() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - FirTree chrismasTree = new FirTree(); - s.persist(chrismasTree); - tx.commit(); - s.clear(); - tx = s.beginTransaction(); - chrismasTree = (FirTree) s.get(FirTree.class, chrismasTree.getId()); - assertNotNull(chrismasTree); - s.delete(chrismasTree); - tx.commit(); - s.close(); - } - - @Test - public void testIdClass() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Footballer fb = new Footballer("David", "Beckam", "Arsenal"); - GoalKeeper keeper = new GoalKeeper("Fabien", "Bartez", "OM"); - s.persist(fb); - s.persist(keeper); - tx.commit(); - s.clear(); - - // lookup by id - tx = s.beginTransaction(); - FootballerPk fpk = new FootballerPk("David", "Beckam"); - fb = (Footballer) s.get(Footballer.class, fpk); - FootballerPk fpk2 = new FootballerPk("Fabien", "Bartez"); - keeper = (GoalKeeper) s.get(GoalKeeper.class, fpk2); - assertNotNull(fb); - assertNotNull(keeper); - assertEquals("Beckam", fb.getLastname()); - assertEquals("Arsenal", fb.getClub()); - assertEquals(1, s.createQuery( - "from Footballer f where f.firstname = 'David'").list().size()); - tx.commit(); - - // reattach by merge - tx = s.beginTransaction(); - fb.setClub("Bimbo FC"); - s.merge(fb); - tx.commit(); - - // reattach by saveOrUpdate - tx = s.beginTransaction(); - fb.setClub("Bimbo FC SA"); - s.saveOrUpdate(fb); - tx.commit(); - - // clean up - s.clear(); - tx = s.beginTransaction(); - fpk = new FootballerPk("David", "Beckam"); - fb = (Footballer) s.get(Footballer.class, fpk); - assertEquals("Bimbo FC SA", fb.getClub()); - s.delete(fb); - s.delete(keeper); - tx.commit(); - s.close(); - } - - @Test - public void testColumnDefinition() { - Column idCol = (Column) metadata().getEntityBinding( Ball.class.getName() ) - .getIdentifierProperty() - .getValue() - .getColumnIterator() - .next(); - assertEquals( "ball_id", idCol.getName() ); - } - - @Test - public void testLowAllocationSize() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - int size = 4; - BreakDance[] bds = new BreakDance[size]; - for (int i = 0; i < size; i++) { - bds[i] = new BreakDance(); - s.persist(bds[i]); - } - s.flush(); - for (int i = 0; i < size; i++) { - assertEquals(i + 1, bds[i].id.intValue()); - } - tx.rollback(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Ball.class, Shoe.class, Store.class, - Department.class, Dog.class, Computer.class, Home.class, - Phone.class, Tree.class, FirTree.class, Footballer.class, - SoundSystem.class, Furniture.class, GoalKeeper.class, - BreakDance.class, Monkey.class, Hotel.class }; - } - - @Override - protected String[] getAnnotatedPackages() { - return new String[] { "org.hibernate.test.annotations", - "org.hibernate.test.annotations.id" }; - } - - @Override - protected String[] getXmlFiles() { - return new String[] { "org/hibernate/test/annotations/orm.xml" }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java deleted file mode 100644 index 9c0adaca22..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/EnumIdTest.java +++ /dev/null @@ -1,65 +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.id.sequences; - -import org.jboss.logging.Logger; -import org.junit.Test; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.test.annotations.id.sequences.entities.Planet; -import org.hibernate.test.annotations.id.sequences.entities.PlanetCheatSheet; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -/** - * Tests for enum type as id. - * - * @author Hardy Ferentschik - */ -@SuppressWarnings("unchecked") -@TestForIssue( jiraKey = "ANN-744" ) -public class EnumIdTest extends BaseCoreFunctionalTestCase { - - @Test - public void testEnumAsId() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - PlanetCheatSheet mercury = new PlanetCheatSheet(); - mercury.setPlanet(Planet.MERCURY); - mercury.setMass(3.303e+23); - mercury.setRadius(2.4397e6); - mercury.setNumberOfInhabitants(0); - s.persist(mercury); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet()); - assertNotNull(mercuryFromDb); - log.debug(mercuryFromDb.toString()); - s.delete(mercuryFromDb); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY); - assertNull(mercury); - tx.commit(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { PlanetCheatSheet.class }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java deleted file mode 100644 index 2117b99b5f..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/HibernateSequenceTest.java +++ /dev/null @@ -1,75 +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.id.sequences; - -import org.junit.Assert; -import org.junit.Test; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.cfg.Configuration; -import org.hibernate.cfg.Environment; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.id.IdentifierGenerator; -import org.hibernate.id.enhanced.SequenceStyleGenerator; -import org.hibernate.mapping.Table; -import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.test.annotations.id.sequences.entities.HibernateSequenceEntity; -import org.hibernate.testing.RequiresDialect; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -/** - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -@TestForIssue(jiraKey = "HHH-6068") -@RequiresDialect( value = H2Dialect.class) -public class HibernateSequenceTest extends BaseCoreFunctionalTestCase { - private static final String SCHEMA_NAME = "OTHER_SCHEMA"; - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - HibernateSequenceEntity.class - }; - } - - @Override - protected void configure(Configuration cfg) { - super.configure( cfg ); - cfg.addResource( "org/hibernate/test/annotations/id/sequences/orm.xml" ); - } - - @Override - protected String createSecondSchema() { - return SCHEMA_NAME; - } - - @Test - public void testHibernateSequenceSchema() { - EntityPersister persister = sessionFactory().getEntityPersister( HibernateSequenceEntity.class.getName() ); - IdentifierGenerator generator = persister.getIdentifierGenerator(); - Assert.assertTrue( SequenceStyleGenerator.class.isInstance( generator ) ); - SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator; - Assert.assertEquals( - Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ), - seqGenerator.getDatabaseStructure().getName() - ); - } - - @Test - public void testHibernateSequenceNextVal() { - Session session = openSession(); - Transaction txn = session.beginTransaction(); - HibernateSequenceEntity entity = new HibernateSequenceEntity(); - entity.setText( "sample text" ); - session.save( entity ); - txn.commit(); - session.close(); - Assert.assertNotNull( entity.getId() ); - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java deleted file mode 100644 index 0c21df9193..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java +++ /dev/null @@ -1,350 +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.id.sequences; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.mapping.Column; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; -import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity1; -import org.hibernate.test.annotations.id.generationmappings.DedicatedSequenceEntity2; -import org.hibernate.test.annotations.id.sequences.entities.Ball; -import org.hibernate.test.annotations.id.sequences.entities.BreakDance; -import org.hibernate.test.annotations.id.sequences.entities.Computer; -import org.hibernate.test.annotations.id.sequences.entities.Department; -import org.hibernate.test.annotations.id.sequences.entities.Dog; -import org.hibernate.test.annotations.id.sequences.entities.FirTree; -import org.hibernate.test.annotations.id.sequences.entities.Footballer; -import org.hibernate.test.annotations.id.sequences.entities.FootballerPk; -import org.hibernate.test.annotations.id.sequences.entities.Furniture; -import org.hibernate.test.annotations.id.sequences.entities.GoalKeeper; -import org.hibernate.test.annotations.id.sequences.entities.Home; -import org.hibernate.test.annotations.id.sequences.entities.Monkey; -import org.hibernate.test.annotations.id.sequences.entities.Phone; -import org.hibernate.test.annotations.id.sequences.entities.Shoe; -import org.hibernate.test.annotations.id.sequences.entities.SoundSystem; -import org.hibernate.test.annotations.id.sequences.entities.Store; -import org.hibernate.test.annotations.id.sequences.entities.Tree; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; - -/** - * @author Emmanuel Bernard - * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) - */ -@SuppressWarnings("unchecked") -@RequiresDialectFeature(DialectChecks.SupportsSequences.class) -public class IdTest extends BaseNonConfigCoreFunctionalTestCase { - @Test - public void testGenericGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - SoundSystem system = new SoundSystem(); - system.setBrand( "Genelec" ); - system.setModel( "T234" ); - Furniture fur = new Furniture(); - s.persist( system ); - s.persist( fur ); - tx.commit(); - s.close(); - - s = openSession(); - tx = s.beginTransaction(); - system = ( SoundSystem ) s.get( SoundSystem.class, system.getId() ); - fur = ( Furniture ) s.get( Furniture.class, fur.getId() ); - assertNotNull( system ); - assertNotNull( fur ); - s.delete( system ); - s.delete( fur ); - tx.commit(); - s.close(); - - } - - @Test - public void testGenericGenerators() throws Exception { - // Ensures that GenericGenerator annotations wrapped inside a GenericGenerators holder are bound correctly - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Monkey monkey = new Monkey(); - s.persist( monkey ); - s.flush(); - assertNotNull( monkey.getId() ); - tx.rollback(); - s.close(); - } - - @Test - public void testTableGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - - Ball b = new Ball(); - Dog d = new Dog(); - Computer c = new Computer(); - s.persist( b ); - s.persist( d ); - s.persist( c ); - tx.commit(); - s.close(); - assertEquals( "table id not generated", new Integer( 1 ), b.getId() ); - assertEquals( - "generator should not be shared", new Integer( 1 ), d - .getId() - ); - assertEquals( "default value should work", new Long( 1 ), c.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - s.delete( s.get( Ball.class, new Integer( 1 ) ) ); - s.delete( s.get( Dog.class, new Integer( 1 ) ) ); - s.delete( s.get( Computer.class, new Long( 1 ) ) ); - tx.commit(); - s.close(); - } - - @Test - public void testSequenceGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Shoe b = new Shoe(); - s.persist( b ); - tx.commit(); - s.close(); - assertNotNull( b.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - s.delete( s.get( Shoe.class, b.getId() ) ); - tx.commit(); - s.close(); - } - - @Test - public void testClassLevelGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Store b = new Store(); - s.persist( b ); - tx.commit(); - s.close(); - assertNotNull( b.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - s.delete( s.get( Store.class, b.getId() ) ); - tx.commit(); - s.close(); - } - - @Test - public void testMethodLevelGenerator() throws Exception { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - Department b = new Department(); - s.persist( b ); - tx.commit(); - s.close(); - assertNotNull( b.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - s.delete( s.get( Department.class, b.getId() ) ); - tx.commit(); - s.close(); - } - - @Test - public void testDefaultSequence() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Home h = new Home(); - s.persist( h ); - tx.commit(); - s.close(); - assertNotNull( h.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - Home reloadedHome = ( Home ) s.get( Home.class, h.getId() ); - assertEquals( h.getId(), reloadedHome.getId() ); - s.delete( reloadedHome ); - tx.commit(); - s.close(); - } - - @Test - public void testParameterizedAuto() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Home h = new Home(); - s.persist( h ); - tx.commit(); - s.close(); - assertNotNull( h.getId() ); - - s = openSession(); - tx = s.beginTransaction(); - Home reloadedHome = ( Home ) s.get( Home.class, h.getId() ); - assertEquals( h.getId(), reloadedHome.getId() ); - s.delete( reloadedHome ); - tx.commit(); - s.close(); - } - - @Test - public void testIdInEmbeddableSuperclass() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - FirTree chrismasTree = new FirTree(); - s.persist( chrismasTree ); - tx.commit(); - s.clear(); - tx = s.beginTransaction(); - chrismasTree = ( FirTree ) s.get( FirTree.class, chrismasTree.getId() ); - assertNotNull( chrismasTree ); - s.delete( chrismasTree ); - tx.commit(); - s.close(); - } - - @Test - public void testIdClass() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Footballer fb = new Footballer( "David", "Beckam", "Arsenal" ); - GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" ); - s.persist( fb ); - s.persist( keeper ); - tx.commit(); - s.clear(); - - // lookup by id - tx = s.beginTransaction(); - FootballerPk fpk = new FootballerPk( "David", "Beckam" ); - fb = ( Footballer ) s.get( Footballer.class, fpk ); - FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" ); - keeper = ( GoalKeeper ) s.get( GoalKeeper.class, fpk2 ); - assertNotNull( fb ); - assertNotNull( keeper ); - assertEquals( "Beckam", fb.getLastname() ); - assertEquals( "Arsenal", fb.getClub() ); - assertEquals( - 1, s.createQuery( - "from Footballer f where f.firstname = 'David'" - ).list().size() - ); - tx.commit(); - - // reattach by merge - tx = s.beginTransaction(); - fb.setClub( "Bimbo FC" ); - s.merge( fb ); - tx.commit(); - - // reattach by saveOrUpdate - tx = s.beginTransaction(); - fb.setClub( "Bimbo FC SA" ); - s.saveOrUpdate( fb ); - tx.commit(); - - // clean up - s.clear(); - tx = s.beginTransaction(); - fpk = new FootballerPk( "David", "Beckam" ); - fb = ( Footballer ) s.get( Footballer.class, fpk ); - assertEquals( "Bimbo FC SA", fb.getClub() ); - s.delete( fb ); - s.delete( keeper ); - tx.commit(); - s.close(); - } - - @Test - @TestForIssue(jiraKey = "HHH-6790") - public void testSequencePerEntity() { - Session session = openSession(); - session.beginTransaction(); - DedicatedSequenceEntity1 entity1 = new DedicatedSequenceEntity1(); - DedicatedSequenceEntity2 entity2 = new DedicatedSequenceEntity2(); - session.persist( entity1 ); - session.persist( entity2 ); - session.getTransaction().commit(); - - assertEquals( 1, entity1.getId().intValue() ); - assertEquals( 1, entity2.getId().intValue() ); - - session.close(); - } - - @Test - public void testColumnDefinition() { - Column idCol = ( Column ) metadata().getEntityBinding( Ball.class.getName() ) - .getIdentifierProperty().getValue().getColumnIterator().next(); - assertEquals( "ball_id", idCol.getName() ); - } - - @Test - public void testLowAllocationSize() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - int size = 4; - BreakDance[] bds = new BreakDance[size]; - for ( int i = 0; i < size; i++ ) { - bds[i] = new BreakDance(); - s.persist( bds[i] ); - } - s.flush(); - for ( int i = 0; i < size; i++ ) { - assertEquals( i + 1, bds[i].id.intValue() ); - } - tx.rollback(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Ball.class, Shoe.class, Store.class, - Department.class, Dog.class, Computer.class, Home.class, - Phone.class, Tree.class, FirTree.class, Footballer.class, - SoundSystem.class, Furniture.class, GoalKeeper.class, - BreakDance.class, Monkey.class, DedicatedSequenceEntity1.class, - DedicatedSequenceEntity2.class - }; - } - - @Override - protected String[] getAnnotatedPackages() { - return new String[] { - "org.hibernate.test.annotations", - "org.hibernate.test.annotations.id", - "org.hibernate.test.annotations.id.generationmappings" - }; - } - - @Override - protected String[] getXmlFiles() { - return new String[] { "org/hibernate/test/annotations/orm.xml" }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassCompositePKTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassCompositePKTest.java deleted file mode 100644 index c3c898d27a..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/IdClassCompositePKTest.java +++ /dev/null @@ -1,45 +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 . - */ - -// $Id$ - -package org.hibernate.test.annotations.idclass; - -import org.junit.Test; - -import org.hibernate.query.Query; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; - -/** - * @author Stale W. Pedersen - */ -public class IdClassCompositePKTest extends BaseCoreFunctionalTestCase { - @Test - public void testEntityMappningPropertiesAreNotIgnored() { - Session s = openSession(); - Transaction tx = s.beginTransaction(); - DomainAdmin da = new DomainAdmin(); - da.setAdminUser( "admin" ); - da.setDomainName( "org" ); - - s.persist( da ); - Query q = s.getNamedQuery( "DomainAdmin.testQuery" ); - assertEquals( 1, q.list().size() ); - - tx.rollback(); - s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { DomainAdmin.class }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java deleted file mode 100644 index b305f03fad..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java +++ /dev/null @@ -1,52 +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.idclass.xml; - -import org.junit.Test; - -import org.hibernate.testing.FailureExpected; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -/** - * A test for HHH-4282 - * - * @author Hardy Ferentschik - */ -@FailureExpected( jiraKey = "HHH-4282" ) -public class IdClassXmlTest extends BaseCoreFunctionalTestCase { - @Test - public void testEntityMappingPropertiesAreNotIgnored() { - throw new RuntimeException(); -// Session s = openSession(); -// Transaction tx = s.beginTransaction(); -// -// HabitatSpeciesLink link = new HabitatSpeciesLink(); -// link.setHabitatId( 1l ); -// link.setSpeciesId( 1l ); -// s.persist( link ); -// -// Query q = s.getNamedQuery( "testQuery" ); -// assertEquals( 1, q.list().size() ); -// -// tx.rollback(); -// s.close(); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - HabitatSpeciesLink.class - }; - } - - @Override - protected String[] getOrmXmlFiles() { - return new String[] { - "org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml" - }; - } -} diff --git a/hibernate-core/src/test/resources/org/hibernate/test/annotations/id/sequences/orm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/id/sequences/orm.xml similarity index 100% rename from hibernate-core/src/test/resources/org/hibernate/test/annotations/id/sequences/orm.xml rename to hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/id/sequences/orm.xml diff --git a/hibernate-core/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.xml similarity index 77% rename from hibernate-core/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml rename to hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.xml index 440fafbc31..2a42bc6a6c 100644 --- a/hibernate-core/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml +++ b/hibernate-core/src/test/resources/org/hibernate/orm/test/annotations/idclass/xml/HabitatSpeciesLink.xml @@ -9,12 +9,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0"> - + + class="org.hibernate.orm.test.annotations.idclass.xml.HabitatSpeciesLink$HabitatSpeciesLinkId"/> + result-class="org.hibernate.orm.test.annotations.idclass.xml.HabitatSpeciesLink"> select * from HABITAT_SPECIES_LINK link where link.HABITAT_LINK = 1 diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java index 572425bf22..6964c91fd3 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DomainModelExtension.java @@ -90,7 +90,7 @@ public class DomainModelExtension final MetadataSources metadataSources = new MetadataSources( serviceRegistry ); for ( String annotatedPackageName : domainModelAnnotation.annotatedPackageNames() ) { - metadataSources.addPackage( JavaHelper.getPackageFor( annotatedPackageName ) ); + metadataSources.addPackage( annotatedPackageName ); } for ( StandardDomainModel standardDomainModel : domainModelAnnotation.standardModels() ) { diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactory.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactory.java index 6f42025e75..b2ccddf541 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactory.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactory.java @@ -44,6 +44,8 @@ public @interface SessionFactory { boolean generateStatistics() default false; boolean exportSchema() default true; + boolean createSecondarySchemas() default false; + Class interceptorClass() default Interceptor.class; Class statementInspectorClass() default StatementInspector.class; diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java index ca4cb5cb29..4e01c30422 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/SessionFactoryExtension.java @@ -20,6 +20,7 @@ import org.hibernate.boot.SessionFactoryBuilder; import org.hibernate.boot.registry.StandardServiceRegistry; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.AvailableSettings; +import org.hibernate.dialect.H2Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.internal.util.StringHelper; @@ -29,6 +30,7 @@ import org.hibernate.tool.schema.Action; import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator; import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.ActionGrouping; +import org.hibernate.testing.junit4.Helper; import org.junit.jupiter.api.extension.AfterAllCallback; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; @@ -108,7 +110,7 @@ public class SessionFactoryExtension final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) sessionFactoryBuilder.build(); if ( sessionFactoryConfig.exportSchema() ) { - prepareSchemaExport( sessionFactory, model ); + prepareSchemaExport( sessionFactory, model, sessionFactoryConfig.createSecondarySchemas() ); } return sessionFactory; @@ -140,7 +142,8 @@ public class SessionFactoryExtension private static void prepareSchemaExport( SessionFactoryImplementor sessionFactory, - MetadataImplementor model) { + MetadataImplementor model, + boolean createSecondarySchemas) { final Map baseProperties = sessionFactory.getProperties(); final ActionGrouping actions = ActionGrouping.interpret( baseProperties ); @@ -154,10 +157,15 @@ public class SessionFactoryExtension final HashMap settings = new HashMap<>( baseProperties ); //noinspection unchecked settings.put( AvailableSettings.HBM2DDL_DATABASE_ACTION, Action.CREATE_DROP ); - + if ( createSecondarySchemas ) { + if ( !( model.getDatabase().getDialect().canCreateSchema() ) ) { + throw new UnsupportedOperationException( + model.getDatabase().getDialect() + " does not support schema creation" ); + } + settings.put( AvailableSettings.HBM2DDL_CREATE_SCHEMAS, true ); + } final StandardServiceRegistry serviceRegistry = model.getMetadataBuildingOptions().getServiceRegistry(); - SchemaManagementToolCoordinator.process( model, serviceRegistry, @@ -171,6 +179,8 @@ public class SessionFactoryExtension } ) ); + + } @Override