From 2fb1cdcae158bd47afce60aad55aefc04b179d3e Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Wed, 17 Feb 2021 23:44:09 +0100 Subject: [PATCH] Migrate more tests from jpa/test to orm/test/jpa Signed-off-by: Jan Schatteman --- .../org/hibernate/jpa/test/lob/BlobTest.java | 60 ----- ...thExplicitReferenceToPrimaryTableTest.java | 59 ----- .../jpa/test/mapping/DefaultCascadeTest.java | 72 ------ ...nidirectionalOneToManyIndexColumnTest.java | 110 --------- ...nidirectionalOneToManyOrderColumnTest.java | 183 -------------- ...ToManyUniqueConstraintOrderColumnTest.java | 173 -------------- .../hibernate/orm/test/jpa/lob/BlobTest.java | 72 ++++++ .../test/jpa}/lob/ImageReader.java | 2 +- ...ctionalOneToManyNotNullableColumnTest.java | 77 +++--- ...thExplicitReferenceToPrimaryTableTest.java | 50 ++++ .../test/jpa/mapping/DefaultCascadeTest.java | 95 ++++++++ ...nidirectionalOneToManyIndexColumnTest.java | 135 +++++++++++ ...nidirectionalOneToManyOrderColumnTest.java | 223 ++++++++++++++++++ ...ToManyUniqueConstraintOrderColumnTest.java | 182 ++++++++++++++ .../attribute/AbstractNameable.java | 2 +- .../MappedSuperclassWithAttributesTest.java | 17 +- .../mappedsuperclass/attribute/Product.java | 2 +- .../embedded/AbstractAddressable.java | 2 +- .../mappedsuperclass/embedded/Address.java | 2 +- .../mappedsuperclass/embedded/Company.java | 2 +- .../MappedSuperclassWithEmbeddedTest.java | 19 +- .../embeddedid/AbstractProduct.java | 2 +- .../MappedSuperclassWithEmbeddedIdTest.java | 23 +- .../mappedsuperclass/embeddedid/Product.java | 2 +- .../embeddedid/ProductId.java | 2 +- .../idclass/AbstractAttribute.java | 2 +- .../idclass/AbstractAttributeId.java | 2 +- ...edSuperclassWithEntityWithIdClassTest.java | 21 +- .../idclass/ProductAttribute.java | 2 +- .../idclass/ProductAttributeId.java | 2 +- .../overridden/AbstractProduct.java | 2 +- ...SuperclassWithOverriddenAttributeTest.java | 23 +- .../mappedsuperclass/overridden/Product1.java | 2 +- .../mappedsuperclass/overridden/Product2.java | 2 +- .../schemaupdate/Hbm2ddlCreateOnlyTest.java | 2 +- .../test => orm/test/jpa}/mapping/orm.xml | 0 36 files changed, 869 insertions(+), 759 deletions(-) delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/lob/BlobTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/DefaultCascadeTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyIndexColumnTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyOrderColumnTest.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/BlobTest.java rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/lob/ImageReader.java (96%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/mapping/BidirectionalOneToManyNotNullableColumnTest.java (53%) create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/DefaultCascadeTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/attribute/AbstractNameable.java (90%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java (60%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/attribute/Product.java (89%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embedded/AbstractAddressable.java (90%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embedded/Address.java (92%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embedded/Company.java (89%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java (60%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embeddedid/AbstractProduct.java (90%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java (54%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embeddedid/Product.java (89%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/embeddedid/ProductId.java (91%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/idclass/AbstractAttribute.java (93%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/idclass/AbstractAttributeId.java (89%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java (56%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/idclass/ProductAttribute.java (93%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/idclass/ProductAttributeId.java (95%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/overridden/AbstractProduct.java (92%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java (64%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/overridden/Product1.java (92%) rename hibernate-core/src/test/java/org/hibernate/{jpa/test => orm/test/jpa}/metagen/mappedsuperclass/overridden/Product2.java (91%) rename hibernate-core/src/test/resources/org/hibernate/{jpa/test => orm/test/jpa}/mapping/orm.xml (100%) diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/lob/BlobTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/lob/BlobTest.java deleted file mode 100644 index 43a92b831b..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/lob/BlobTest.java +++ /dev/null @@ -1,60 +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.jpa.test.lob; - -import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.HashMap; -import java.util.Map; -import javax.persistence.EntityManager; - -import org.junit.Test; - -import org.hibernate.Session; -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - -import org.hibernate.testing.DialectChecks; -import org.hibernate.testing.RequiresDialectFeature; - -import static org.junit.Assert.assertTrue; - -/** - * @author Emmanuel Bernard - */ -@RequiresDialectFeature( DialectChecks.SupportsExpectedLobUsagePattern.class ) -public class BlobTest extends BaseEntityManagerFunctionalTestCase { - @Test - public void testBlobSerialization() throws Exception { - EntityManager em = getOrCreateEntityManager(); - em.getTransaction().begin(); - Map image = new HashMap(); - image.put( "meta", "metadata" ); - image.put( "data", "imagedata" ); - ImageReader reader = new ImageReader(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream( baos ); - oos.writeObject( image ); - reader.setImage( em.unwrap( Session.class ).getLobHelper().createBlob( baos.toByteArray() ) ); - em.persist( reader ); - em.getTransaction().commit(); - em.close(); //useless but y'a know - em = getOrCreateEntityManager(); - em.getTransaction().begin(); - reader = em.find( ImageReader.class, reader.getId() ); - ObjectInputStream ois = new ObjectInputStream( reader.getImage().getBinaryStream() ); - image = (HashMap) ois.readObject(); - assertTrue( image.containsKey( "meta" ) ); - em.getTransaction().commit(); - em.close(); - } - - @Override - public Class[] getAnnotatedClasses() { - return new Class[] { ImageReader.class }; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java deleted file mode 100644 index f21012ece9..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java +++ /dev/null @@ -1,59 +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.jpa.test.mapping; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Id; -import javax.persistence.Table; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.jpa.boot.spi.Bootstrap; -import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; - -import org.junit.Test; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; - -/** - * @author Steve Ebersole - */ -public class ColumnWithExplicitReferenceToPrimaryTableTest extends BaseUnitTestCase { - @Test - @TestForIssue( jiraKey = "HHH-8539" ) - public void testColumnAnnotationWithExplicitReferenceToPrimaryTable() { - final PersistenceUnitDescriptorAdapter pu = new PersistenceUnitDescriptorAdapter() { - @Override - public List getManagedClassNames() { - return Arrays.asList( AnEntity.class.getName() ); - } - }; - - - final Map settings = new HashMap(); - settings.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" ); - - EntityManagerFactory emf = Bootstrap.getEntityManagerFactoryBuilder( pu, settings ).build(); - emf.close(); - } - - @Entity - @Table( name = "THE_TABLE" ) - public static class AnEntity { - @Id - public Integer id; - @Column( name = "THE_COLUMN", table = "THE_TABLE" ) - public String theValue; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/DefaultCascadeTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/DefaultCascadeTest.java deleted file mode 100644 index 1b6064f267..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/DefaultCascadeTest.java +++ /dev/null @@ -1,72 +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.jpa.test.mapping; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; - -/** - * @author Vlad Mihalcea - */ -public class DefaultCascadeTest extends BaseEntityManagerFunctionalTestCase { - - @Test - public void testCascadePersist() { - doInJPA( this::entityManagerFactory, entityManager -> { - Parent parent = new Parent(); - Child child = new Child(); - child.parent = parent; - - entityManager.persist( child ); - } ); - } - - @Override - public String[] getEjb3DD() { - return new String[] { - "org/hibernate/jpa/test/mapping/orm.xml" - }; - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - Parent.class, - Child.class - }; - } - - @Entity - @Table(name = "Parent") - public static class Parent { - - @Id - @GeneratedValue - private Integer id; - } - - @Entity - @Table(name = "Child") - public static class Child { - - @Id - @GeneratedValue - private Integer id; - - @ManyToOne - private Parent parent; - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyIndexColumnTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyIndexColumnTest.java deleted file mode 100644 index e24e6559dd..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyIndexColumnTest.java +++ /dev/null @@ -1,110 +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.jpa.test.mapping; - -import java.util.ArrayList; -import java.util.List; -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -import org.hibernate.annotations.IndexColumn; - -import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; -import org.hibernate.testing.transaction.TransactionUtil; -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -/** - * @author Andrea Boriero - */ -@TestForIssue(jiraKey = "HHH-1268") -public class UnidirectionalOneToManyIndexColumnTest extends BaseCoreFunctionalTestCase { - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { Parent.class, Child.class }; - } - - @Test - public void testRemovingAChild() { - int parentId = TransactionUtil.doInHibernate( this::sessionFactory, session -> { - Parent parent = new Parent(); - parent.getChildren().add( new Child() ); - parent.getChildren().add( new Child() ); - parent.getChildren().add( new Child() ); - session.persist( parent ); - return parent.getId(); - } ); - - TransactionUtil.doInHibernate( this::sessionFactory, session -> { - Parent parent = session.find( Parent.class, parentId ); - List children = parent.getChildren(); - assertThat( children.size(), is( 3 ) ); - children.remove( 0 ); - session.persist( parent ); - } ); - - TransactionUtil.doInHibernate( this::sessionFactory, session -> { - Parent parent = session.find( Parent.class, parentId ); - List children = parent.getChildren(); - assertThat( children.size(), is( 2 ) ); - } ); - } - - - @Entity - @Table(name = "PARENT") - public static class Parent { - - @Id - @GeneratedValue - private int id; - - @OneToMany(targetEntity = Child.class, cascade = CascadeType.ALL) - @IndexColumn(name = "position") - private List children = new ArrayList<>(); - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } - } - - @Entity - @Table(name = "CHILD") - public static class Child { - @Id - @GeneratedValue - private int id; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - } -} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyOrderColumnTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyOrderColumnTest.java deleted file mode 100644 index d75e623b33..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyOrderColumnTest.java +++ /dev/null @@ -1,183 +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.jpa.test.mapping; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.OrderColumn; -import javax.persistence.Table; - -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - -import org.hibernate.testing.TestForIssue; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; -import static org.junit.Assert.assertEquals; - -@TestForIssue(jiraKey = "HHH-11587") -public class UnidirectionalOneToManyOrderColumnTest extends BaseEntityManagerFunctionalTestCase { - - @Test - public void testRemovingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = new ParentData(); - entityManager.persist( parent ); - - String[] childrenStr = new String[] {"One", "Two", "Three"}; - for ( String str : childrenStr ) { - ChildData child = new ChildData( str ); - entityManager.persist( child ); - parent.getChildren().add( child ); - } - - entityManager.flush(); - - List children = parent.getChildren(); - children.remove( 0 ); - } ); - } - - @Test - public void testAddingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = new ParentData(); - entityManager.persist( parent ); - - String[] childrenStr = new String[] {"One", "Two", "Three"}; - for ( String str : childrenStr ) { - ChildData child = new ChildData( str ); - entityManager.persist( child ); - parent.getChildren().add( child ); - } - - entityManager.flush(); - - List children = parent.getChildren(); - children.add( 1, new ChildData( "Another" ) ); - } ); - } - - @Test - public void testRemovingAndAddingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = new ParentData(); - entityManager.persist( parent ); - - String[] childrenStr = new String[] {"One", "Two", "Three"}; - for ( String str : childrenStr ) { - ChildData child = new ChildData( str ); - entityManager.persist( child ); - parent.getChildren().add( child ); - } - - entityManager.flush(); - - List children = parent.getChildren(); - children.remove( 0 ); - children.add( 1, new ChildData( "Another" ) ); - } ); - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = entityManager.find( ParentData.class, 1L ); - List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); - int i = 0; - assertEquals( "Two", childIds.get( i++ )); - assertEquals( "Another", childIds.get( i++ )); - assertEquals( "Three", childIds.get( i++ )); - } ); - } - - @Test - public void testRemovingOneAndAddingTwoElements() { - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = new ParentData(); - entityManager.persist( parent ); - - String[] childrenStr = new String[] {"One", "Two", "Three"}; - for ( String str : childrenStr ) { - ChildData child = new ChildData( str ); - entityManager.persist( child ); - parent.getChildren().add( child ); - } - - entityManager.flush(); - - List children = parent.getChildren(); - children.remove( 0 ); - children.add( 1, new ChildData( "Another" ) ); - children.add( new ChildData( "Another Another" ) ); - } ); - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = entityManager.find( ParentData.class, 1L ); - List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); - int i = 0; - assertEquals( "Two", childIds.get( i++ )); - assertEquals( "Another", childIds.get( i++ )); - assertEquals( "Three", childIds.get( i++ )); - assertEquals( "Another Another", childIds.get( i++ )); - } ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - ParentData.class, - ChildData.class - }; - } - - @Entity(name = "ParentData") - @Table(name = "PARENT") - public static class ParentData { - @Id - @GeneratedValue - long id; - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @OrderColumn(name = "listOrder") - private List children = new ArrayList<>(); - - public List getChildren() { - return children; - } - } - - @Entity(name = "ChildData") - @Table(name = "CHILD") - public static class ChildData { - @Id - @GeneratedValue - long id; - - String childId; - - public ChildData() { - } - - public ChildData(String id) { - childId = id; - } - - @Override - public String toString() { - return childId; - } - } - -} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java deleted file mode 100644 index adfcb1b73b..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java +++ /dev/null @@ -1,173 +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.jpa.test.mapping; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; -import javax.persistence.CascadeType; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.OrderColumn; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; - -import org.hibernate.testing.FailureExpected; -import org.hibernate.testing.TestForIssue; -import org.junit.Test; - -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; -import static org.junit.Assert.assertEquals; - -@TestForIssue(jiraKey = "HHH-1268") -public class UnidirectionalOneToManyUniqueConstraintOrderColumnTest extends BaseEntityManagerFunctionalTestCase { - - @Override - protected void afterEntityManagerFactoryBuilt() { - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = new ParentData(); - parent.id = 1L; - entityManager.persist( parent ); - - String[] childrenStr = new String[] {"One", "Two", "Three"}; - for ( String str : childrenStr ) { - ChildData child = new ChildData( str ); - parent.getChildren().add( child ); - } - } ); - } - - @Test - @FailureExpected( jiraKey = "HHH-1268" ) - public void testRemovingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - List children = parent.getChildren(); - children.remove( 0 ); - } ); - } - - @Test - @FailureExpected( jiraKey = "HHH-1268" ) - public void testAddingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - List children = parent.getChildren(); - children.add( 1, new ChildData( "Another" ) ); - } ); - } - - @Test - @FailureExpected( jiraKey = "HHH-1268" ) - public void testRemovingAndAddingAnElement() { - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - List children = parent.getChildren(); - children.remove( 0 ); - children.add( 1, new ChildData( "Another" ) ); - } ); - - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - List childIds = parent.getChildren() - .stream() - .map( ChildData::toString ) - .collect( Collectors.toList() ); - - int i = 0; - - assertEquals( "Two", childIds.get( i++ )); - assertEquals( "Another", childIds.get( i++ )); - assertEquals( "Three", childIds.get( i )); - } ); - } - - @Test - @FailureExpected( jiraKey = "HHH-1268" ) - public void testRemovingOneAndAddingTwoElements() { - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - List children = parent.getChildren(); - children.remove( 0 ); - children.add( 1, new ChildData( "Another" ) ); - children.add( new ChildData( "Another Another" ) ); - } ); - - doInJPA( this::entityManagerFactory, entityManager -> { - - ParentData parent = entityManager.find( ParentData.class, 1L ); - List childIds = parent.getChildren() - .stream() - .map( ChildData::toString ) - .collect( Collectors.toList() ); - - int i = 0; - - assertEquals( "Two", childIds.get( i++ ) ); - assertEquals( "Another", childIds.get( i++ ) ); - assertEquals( "Three", childIds.get( i++ ) ); - assertEquals( "Another Another", childIds.get( i ) ); - } ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - ParentData.class, - ChildData.class - }; - } - - @Entity(name = "ParentData") - public static class ParentData { - @Id - long id; - - @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) - @JoinColumn(name = "parentId", nullable = false) - @OrderColumn(name = "listOrder") - private List children = new ArrayList<>(); - - public List getChildren() { - return children; - } - } - - @Entity(name = "ChildData") - @Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "parentId", "listOrder" }) }) - public static class ChildData { - @Id - @GeneratedValue - long id; - - String childId; - - public ChildData() { - } - - public ChildData(String id) { - childId = id; - } - - @Override - public String toString() { - return childId; - } - } - -} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/BlobTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/BlobTest.java new file mode 100644 index 0000000000..96c243d0aa --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/BlobTest.java @@ -0,0 +1,72 @@ +/* + * 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.jpa.lob; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.HashMap; +import java.util.Map; +import javax.persistence.EntityManager; + +import org.hibernate.Session; + +import org.hibernate.testing.orm.junit.DialectFeatureChecks; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.RequiresDialectFeature; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * @author Emmanuel Bernard + */ +@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsExpectedLobUsagePattern.class) +@Jpa(annotatedClasses = { + ImageReader.class +}) +public class BlobTest { + @Test + public void testBlobSerialization(EntityManagerFactoryScope scope) { + Long readerId = scope.fromTransaction( + entityManager -> { + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream( baos )) { + Map image = new HashMap<>(); + image.put( "meta", "metadata" ); + image.put( "data", "imagedata" ); + ImageReader reader = new ImageReader(); + oos.writeObject( image ); + reader.setImage( entityManager.unwrap( Session.class ) + .getLobHelper() + .createBlob( baos.toByteArray() ) ); + entityManager.persist( reader ); + return reader.getId(); + } + catch (IOException e) { + throw new RuntimeException( e ); + } + } + ); + + scope.inTransaction( + entityManager -> { + ImageReader reader = entityManager.find( ImageReader.class, readerId ); + try (ObjectInputStream ois = new ObjectInputStream( reader.getImage().getBinaryStream() )) { + Map image = (HashMap) ois.readObject(); + assertTrue( image.containsKey( "meta" ) ); + } + catch (Exception e) { + throw new RuntimeException( e ); + } + } + ); + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/lob/ImageReader.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/ImageReader.java similarity index 96% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/lob/ImageReader.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/ImageReader.java index a4ed2b520e..a0f1900d60 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/lob/ImageReader.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/lob/ImageReader.java @@ -6,7 +6,7 @@ */ //$Id$ -package org.hibernate.jpa.test.lob; +package org.hibernate.orm.test.jpa.lob; import java.io.Serializable; import java.sql.Blob; import java.sql.Clob; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/BidirectionalOneToManyNotNullableColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/BidirectionalOneToManyNotNullableColumnTest.java similarity index 53% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/BidirectionalOneToManyNotNullableColumnTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/BidirectionalOneToManyNotNullableColumnTest.java index 76792c85e3..76dd31b466 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/mapping/BidirectionalOneToManyNotNullableColumnTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/BidirectionalOneToManyNotNullableColumnTest.java @@ -4,61 +4,67 @@ * 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.jpa.test.mapping; +package org.hibernate.orm.test.jpa.mapping; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; -import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OrderColumn; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; -import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; +import org.hibernate.testing.orm.junit.FailureExpected; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.Jpa; -import org.hibernate.testing.FailureExpected; -import org.hibernate.testing.TestForIssue; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertSame; + +@JiraKey(value = "HHH-13287") +@Jpa(annotatedClasses = { + BidirectionalOneToManyNotNullableColumnTest.ParentData.class, + BidirectionalOneToManyNotNullableColumnTest.ChildData.class +}) +public class BidirectionalOneToManyNotNullableColumnTest { + + @AfterEach + public void tearDown(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + entityManager.createQuery( "delete from ChildData" ).executeUpdate(); + entityManager.createQuery( "delete from ParentData" ).executeUpdate(); + } + ); + } -@TestForIssue(jiraKey = "HHH-13287") -public class BidirectionalOneToManyNotNullableColumnTest extends BaseEntityManagerFunctionalTestCase { @Test @FailureExpected( jiraKey = "HHH-13287" ) - public void test() { - doInJPA( this::entityManagerFactory, entityManager -> { + public void test(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = new ParentData(); + parent.setId( 1L ); + parent.addChildData( new ChildData() ); + parent.addChildData( new ChildData() ); - ParentData parent = new ParentData(); - parent.setId( 1L ); - parent.addChildData( new ChildData() ); - parent.addChildData( new ChildData() ); + entityManager.persist( parent ); + } + ); - entityManager.persist( parent ); - } ); + scope.inTransaction( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); - doInJPA( this::entityManagerFactory, entityManager -> { - ParentData parent = entityManager.find( ParentData.class, 1L ); - - assertSame( 2, parent.getChildren().size() ); - } ); - } - - @Override - protected Class[] getAnnotatedClasses() { - return new Class[] { - ParentData.class, - ChildData.class - }; + assertSame( 2, parent.getChildren().size() ); + } + ); } @Entity(name = "ParentData") @@ -116,5 +122,4 @@ public class BidirectionalOneToManyNotNullableColumnTest extends BaseEntityManag this.parentData = parentData; } } - } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java new file mode 100644 index 0000000000..a271cc6935 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/ColumnWithExplicitReferenceToPrimaryTableTest.java @@ -0,0 +1,50 @@ +/* + * 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.jpa.mapping; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.cfg.AvailableSettings; + +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + + +/** + * @author Steve Ebersole + */ +@Jpa( + annotatedClasses = { + ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity.class + }, + integrationSettings = { @Setting(name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop") } +) +public class ColumnWithExplicitReferenceToPrimaryTableTest { + @Test + @JiraKey( value = "HHH-8539" ) + public void testColumnAnnotationWithExplicitReferenceToPrimaryTable(EntityManagerFactoryScope scope) { + Assertions.assertNotNull( scope.getEntityManagerFactory() ); + scope.getEntityManagerFactory().close(); + } + + @Entity + @Table( name = "THE_TABLE" ) + public static class AnEntity { + @Id + public Integer id; + @Column( name = "THE_COLUMN", table = "THE_TABLE" ) + public String theValue; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/DefaultCascadeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/DefaultCascadeTest.java new file mode 100644 index 0000000000..4721602880 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/DefaultCascadeTest.java @@ -0,0 +1,95 @@ +/* + * 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.jpa.mapping; + +import java.util.Arrays; +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +import org.hibernate.cfg.AvailableSettings; + +import org.hibernate.testing.orm.jpa.NonStringValueSettingProvider; +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +/** + * @author Vlad Mihalcea + */ +@Jpa( + annotatedClasses = { + DefaultCascadeTest.Parent.class, + DefaultCascadeTest.Child.class + }, + // using 'xmlMappings = { "org/hibernate/orm/test/jpa/mapping/orm.xml" }' also works + nonStringValueSettingProviders = { DefaultCascadeTest.EJB3DDMappingProvider.class } +) +public class DefaultCascadeTest { + + @AfterEach + public void tearDown(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + entityManager.createQuery( "delete from DefaultCascadeTest$Child" ).executeUpdate(); + entityManager.createQuery( "delete from DefaultCascadeTest$Parent" ).executeUpdate(); + } + ); + } + + @Test + public void testCascadePersist(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + Parent parent = new Parent(); + Child child = new Child(); + child.parent = parent; + + entityManager.persist( child ); + } + ); + } + + @Entity + @Table(name = "Parent") + public static class Parent { + + @Id + @GeneratedValue + private Integer id; + } + + @Entity + @Table(name = "Child") + public static class Child { + + @Id + @GeneratedValue + private Integer id; + + @ManyToOne + private Parent parent; + } + + public static class EJB3DDMappingProvider extends NonStringValueSettingProvider { + @Override + public String getKey() { + return AvailableSettings.XML_FILE_NAMES; + } + + @Override + public Object getValue() { + return Arrays.asList( "org/hibernate/orm/test/jpa/mapping/orm.xml" ); + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java new file mode 100644 index 0000000000..60bdfd9280 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyIndexColumnTest.java @@ -0,0 +1,135 @@ +/* + * 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.jpa.mapping; + +import java.util.ArrayList; +import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +import org.hibernate.annotations.IndexColumn; +import org.hibernate.cfg.AvailableSettings; + +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; +import org.hibernate.testing.orm.junit.Setting; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.MatcherAssert.assertThat; + +/** + * @author Andrea Boriero + */ +@JiraKey( value = "HHH-1268") +@Jpa( + annotatedClasses = { + UnidirectionalOneToManyIndexColumnTest.Parent.class, + UnidirectionalOneToManyIndexColumnTest.Child.class + }, + integrationSettings = { + @Setting(name = AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, value = "true"), + @Setting(name = AvailableSettings.HBM2DDL_AUTO, value = "create-drop"), + @Setting(name = AvailableSettings.IMPLICIT_NAMING_STRATEGY, value = "org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl") + } +) +public class UnidirectionalOneToManyIndexColumnTest { + + @AfterEach + public void tearDown(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + entityManager.createQuery( "delete from UnidirectionalOneToManyIndexColumnTest$Parent" ).executeUpdate(); + } + ); + } + + @Test + public void testRemovingAChild(EntityManagerFactoryScope scope) { + int parentId = scope.fromTransaction( + entityManager -> { + Parent parent = new Parent(); + parent.getChildren().add( new Child() ); + parent.getChildren().add( new Child() ); + parent.getChildren().add( new Child() ); + entityManager.persist( parent ); + return parent.getId(); + } + ); + + scope.inTransaction( + entityManager -> { + Parent parent = entityManager.find( Parent.class, parentId ); + List children = parent.getChildren(); + assertThat( children.size(), is( 3 ) ); + children.remove( 0 ); + entityManager.persist( parent ); + } + ); + + scope.inEntityManager( + entityManager -> { + Parent parent = entityManager.find( Parent.class, parentId ); + List children = parent.getChildren(); + assertThat( children.size(), is( 2 ) ); + } + ); + } + + + @Entity + @Table(name = "PARENT") + public static class Parent { + + @Id + @GeneratedValue + private int id; + + @OneToMany(targetEntity = Child.class, cascade = CascadeType.ALL) + @IndexColumn(name = "position") + private List children = new ArrayList<>(); + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + } + + @Entity + @Table(name = "CHILD") + public static class Child { + @Id + @GeneratedValue + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java new file mode 100644 index 0000000000..f5b6ead01d --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyOrderColumnTest.java @@ -0,0 +1,223 @@ +/* + * 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.jpa.mapping; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.OrderColumn; +import javax.persistence.Table; + +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@JiraKey(value = "HHH-11587") +@Jpa(annotatedClasses = { + UnidirectionalOneToManyOrderColumnTest.ParentData.class, + UnidirectionalOneToManyOrderColumnTest.ChildData.class +}) +public class UnidirectionalOneToManyOrderColumnTest { + + @AfterEach + public void tearDown(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + entityManager.createQuery( "delete from ParentData" ).executeUpdate(); + } + ); + } + + @Test + public void testRemovingAnElement(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two", "Three"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + children.remove( 0 ); + return parent.id; + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, parentId ); + List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); + int i = 0; + assertEquals( "Two", childIds.get( i++ )); + assertEquals( "Three", childIds.get( i )); + } + ); + } + + @Test + public void testAddingAnElement(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two", "Three"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + children.add( 1, new ChildData( "Another" ) ); + return parent.id; + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, parentId ); + List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); + int i = 0; + assertEquals( "One", childIds.get( i++ )); + assertEquals( "Another", childIds.get( i++ )); + assertEquals( "Two", childIds.get( i++ )); + assertEquals( "Three", childIds.get( i )); + } + ); + } + + @Test + public void testRemovingAndAddingAnElement(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two", "Three"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + children.remove( 0 ); + children.add( 1, new ChildData( "Another" ) ); + return parent.id; + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, parentId ); + List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); + int i = 0; + assertEquals( "Two", childIds.get( i++ )); + assertEquals( "Another", childIds.get( i++ )); + assertEquals( "Three", childIds.get( i )); + } + ); + } + + @Test + public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope) { + long parentId = scope.fromTransaction( + entityManager -> { + ParentData parent = new ParentData(); + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two", "Three"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + entityManager.persist( child ); + parent.getChildren().add( child ); + } + + entityManager.flush(); + + List children = parent.getChildren(); + children.remove( 0 ); + children.add( 1, new ChildData( "Another" ) ); + children.add( new ChildData( "Another Another" ) ); + return parent.id; + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, parentId ); + List childIds = parent.getChildren().stream().map( ChildData::toString ).collect( Collectors.toList() ); + int i = 0; + assertEquals( "Two", childIds.get( i++ )); + assertEquals( "Another", childIds.get( i++ )); + assertEquals( "Three", childIds.get( i++ )); + assertEquals( "Another Another", childIds.get( i )); + } + ); + } + + @Entity(name = "ParentData") + @Table(name = "PARENT") + public static class ParentData { + @Id + @GeneratedValue + long id; + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @OrderColumn(name = "listOrder") + private List children = new ArrayList<>(); + + public List getChildren() { + return children; + } + } + + @Entity(name = "ChildData") + @Table(name = "CHILD") + public static class ChildData { + @Id + @GeneratedValue + long id; + + String childId; + + public ChildData() { + } + + public ChildData(String id) { + childId = id; + } + + @Override + public String toString() { + return childId; + } + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java new file mode 100644 index 0000000000..934dc14fbf --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/mapping/UnidirectionalOneToManyUniqueConstraintOrderColumnTest.java @@ -0,0 +1,182 @@ +/* + * 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.jpa.mapping; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OrderColumn; +import javax.persistence.Table; +import javax.persistence.UniqueConstraint; + +import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; +import org.hibernate.testing.orm.junit.FailureExpected; +import org.hibernate.testing.orm.junit.JiraKey; +import org.hibernate.testing.orm.junit.Jpa; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@JiraKey(value = "HHH-1268") +@Jpa(annotatedClasses = { + UnidirectionalOneToManyUniqueConstraintOrderColumnTest.ParentData.class, + UnidirectionalOneToManyUniqueConstraintOrderColumnTest.ChildData.class +}) +public class UnidirectionalOneToManyUniqueConstraintOrderColumnTest { + + @BeforeAll + protected void init(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = new ParentData(); + parent.id = 1L; + entityManager.persist( parent ); + + String[] childrenStr = new String[] {"One", "Two", "Three"}; + for ( String str : childrenStr ) { + ChildData child = new ChildData( str ); + parent.getChildren().add( child ); + } + } + ); + } + + @Test + @FailureExpected( jiraKey = "HHH-1268" ) + public void testRemovingAnElement(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + + List children = parent.getChildren(); + children.remove( 0 ); + } + ); + } + + @Test + @FailureExpected( jiraKey = "HHH-1268" ) + public void testAddingAnElement(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + + List children = parent.getChildren(); + children.add( 1, new ChildData( "Another" ) ); + } + ); + } + + @Test + @FailureExpected( jiraKey = "HHH-1268" ) + public void testRemovingAndAddingAnElement(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + + List children = parent.getChildren(); + children.remove( 0 ); + children.add( 1, new ChildData( "Another" ) ); + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + + List childIds = parent.getChildren() + .stream() + .map( ChildData::toString ) + .collect( Collectors.toList() ); + + int i = 0; + + assertEquals( "Two", childIds.get( i++ )); + assertEquals( "Another", childIds.get( i++ )); + assertEquals( "Three", childIds.get( i )); + } + ); + } + + @Test + @FailureExpected( jiraKey = "HHH-1268" ) + public void testRemovingOneAndAddingTwoElements(EntityManagerFactoryScope scope) { + scope.inTransaction( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + + List children = parent.getChildren(); + children.remove( 0 ); + children.add( 1, new ChildData( "Another" ) ); + children.add( new ChildData( "Another Another" ) ); + } + ); + + scope.inEntityManager( + entityManager -> { + ParentData parent = entityManager.find( ParentData.class, 1L ); + List childIds = parent.getChildren() + .stream() + .map( ChildData::toString ) + .collect( Collectors.toList() ); + + int i = 0; + + assertEquals( "Two", childIds.get( i++ ) ); + assertEquals( "Another", childIds.get( i++ ) ); + assertEquals( "Three", childIds.get( i++ ) ); + assertEquals( "Another Another", childIds.get( i ) ); + } + ); + } + + @Entity(name = "ParentData") + public static class ParentData { + @Id + long id; + + @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumn(name = "parentId", nullable = false) + @OrderColumn(name = "listOrder") + private List children = new ArrayList<>(); + + public List getChildren() { + return children; + } + } + + @Entity(name = "ChildData") + @Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "parentId", "listOrder" }) }) + public static class ChildData { + @Id + @GeneratedValue + long id; + + String childId; + + public ChildData() { + } + + public ChildData(String id) { + childId = id; + } + + @Override + public String toString() { + return childId; + } + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/AbstractNameable.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/AbstractNameable.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/AbstractNameable.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/AbstractNameable.java index d466341749..36d8153b0e 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/AbstractNameable.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/AbstractNameable.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.jpa.test.metagen.mappedsuperclass.attribute; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.attribute; import javax.persistence.Column; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java similarity index 60% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java index ba056b2522..bef962c7da 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/MappedSuperclassWithAttributesTest.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.jpa.test.metagen.mappedsuperclass.attribute; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.attribute; import java.util.Arrays; import javax.persistence.EntityManagerFactory; @@ -13,16 +13,17 @@ import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.TestingEntityManagerFactoryGenerator; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Steve Ebersole */ @TestForIssue( jiraKey = "HHH-5024" ) -public class MappedSuperclassWithAttributesTest extends BaseUnitTestCase { +@BaseUnitTest +public class MappedSuperclassWithAttributesTest { @Test public void testStaticMetamodel() { EntityManagerFactory emf = TestingEntityManagerFactoryGenerator.generateEntityManagerFactory( @@ -30,10 +31,10 @@ public class MappedSuperclassWithAttributesTest extends BaseUnitTestCase { Arrays.asList( Product.class ) ); try { - assertNotNull( "'Product_.id' should not be null)", Product_.id ); - assertNotNull( "'Product_.name' should not be null)", Product_.name ); + assertNotNull( Product_.id, "'Product_.id' should not be null)" ); + assertNotNull( Product_.name, "'Product_.name' should not be null)" ); - assertNotNull( "'AbstractNameable_.name' should not be null)", AbstractNameable_.name ); + assertNotNull( AbstractNameable_.name, "'AbstractNameable_.name' should not be null)" ); } finally { emf.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/Product.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/Product.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/Product.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/Product.java index 118f07b239..95c9453969 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/attribute/Product.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/attribute/Product.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.jpa.test.metagen.mappedsuperclass.attribute; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.attribute; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/AbstractAddressable.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/AbstractAddressable.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/AbstractAddressable.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/AbstractAddressable.java index cb5fa67ab4..4bdcf4d891 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/AbstractAddressable.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/AbstractAddressable.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.jpa.test.metagen.mappedsuperclass.embedded; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embedded; import javax.persistence.Embedded; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Address.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Address.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Address.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Address.java index f32551edc6..bb43a751c8 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Address.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Address.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.jpa.test.metagen.mappedsuperclass.embedded; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embedded; import javax.persistence.Embeddable; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Company.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Company.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Company.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Company.java index 6d09c8c3d8..5be29791bb 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/Company.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/Company.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.jpa.test.metagen.mappedsuperclass.embedded; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embedded; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java similarity index 60% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java index 43c4a6ba50..4bbaa3d2f1 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embedded/MappedSuperclassWithEmbeddedTest.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.jpa.test.metagen.mappedsuperclass.embedded; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embedded; import javax.persistence.EntityManagerFactory; import java.util.Arrays; @@ -12,17 +12,18 @@ import java.util.Arrays; import org.hibernate.jpa.test.TestingEntityManagerFactoryGenerator; import org.hibernate.jpa.AvailableSettings; -import org.junit.Test; - import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.testing.orm.junit.BaseUnitTest; -import static org.junit.Assert.assertNotNull; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Steve Ebersole */ -public class MappedSuperclassWithEmbeddedTest extends BaseUnitTestCase { +@BaseUnitTest +public class MappedSuperclassWithEmbeddedTest { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { @@ -31,10 +32,10 @@ public class MappedSuperclassWithEmbeddedTest extends BaseUnitTestCase { Arrays.asList( Company.class ) ); try { - assertNotNull( "'Company_.id' should not be null)", Company_.id ); - assertNotNull( "'Company_.address' should not be null)", Company_.address ); + assertNotNull( Company_.id, "'Company_.id' should not be null)" ); + assertNotNull( Company_.address, "'Company_.address' should not be null)" ); - assertNotNull( "'AbstractAddressable_.address' should not be null)", AbstractAddressable_.address ); + assertNotNull( AbstractAddressable_.address, "'AbstractAddressable_.address' should not be null)" ); } finally { emf.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/AbstractProduct.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/AbstractProduct.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/AbstractProduct.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/AbstractProduct.java index c3a19a71fc..c1c59f6737 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/AbstractProduct.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/AbstractProduct.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.jpa.test.metagen.mappedsuperclass.embeddedid; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embeddedid; import java.io.Serializable; import javax.persistence.EmbeddedId; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java similarity index 54% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java index cb97be727e..509c519c07 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/MappedSuperclassWithEmbeddedIdTest.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.jpa.test.metagen.mappedsuperclass.embeddedid; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embeddedid; import javax.persistence.EntityManagerFactory; import java.util.Arrays; @@ -12,17 +12,18 @@ import java.util.Arrays; import org.hibernate.jpa.test.TestingEntityManagerFactoryGenerator; import org.hibernate.jpa.AvailableSettings; -import org.junit.Test; - import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.testing.orm.junit.BaseUnitTest; -import static org.junit.Assert.assertNotNull; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Steve Ebersole */ -public class MappedSuperclassWithEmbeddedIdTest extends BaseUnitTestCase { +@BaseUnitTest +public class MappedSuperclassWithEmbeddedIdTest { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { @@ -32,13 +33,13 @@ public class MappedSuperclassWithEmbeddedIdTest extends BaseUnitTestCase { ); try { - assertNotNull( "'Product_.description' should not be null)", Product_.description ); - assertNotNull( "'Product_.id' should not be null)", Product_.id ); + assertNotNull( Product_.description, "'Product_.description' should not be null)" ); + assertNotNull( Product_.id, "'Product_.id' should not be null)" ); - assertNotNull( "'AbstractProduct_.id' should not be null)", AbstractProduct_.id ); + assertNotNull( AbstractProduct_.id, "'AbstractProduct_.id' should not be null)" ); - assertNotNull( "'ProductId_.id' should not be null)", ProductId_.id ); - assertNotNull( "'ProductId_.code' should not be null)", ProductId_.code ); + assertNotNull( ProductId_.id, "'ProductId_.id' should not be null)" ); + assertNotNull( ProductId_.code, "'ProductId_.code' should not be null)" ); } finally { emf.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/Product.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/Product.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/Product.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/Product.java index ab6dfc1634..d1999ba812 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/Product.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/Product.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.jpa.test.metagen.mappedsuperclass.embeddedid; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embeddedid; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/ProductId.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/ProductId.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/ProductId.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/ProductId.java index 17bdd62594..a4d18f5172 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/embeddedid/ProductId.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/embeddedid/ProductId.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.jpa.test.metagen.mappedsuperclass.embeddedid; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.embeddedid; import java.io.Serializable; import javax.persistence.Column; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttribute.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttribute.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttribute.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttribute.java index ee5498143d..d1e706b0e4 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttribute.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttribute.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.jpa.test.metagen.mappedsuperclass.idclass; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.idclass; import java.io.Serializable; import javax.persistence.Column; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttributeId.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttributeId.java similarity index 89% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttributeId.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttributeId.java index 68c067c336..941250e02f 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/AbstractAttributeId.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/AbstractAttributeId.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.jpa.test.metagen.mappedsuperclass.idclass; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.idclass; import java.io.Serializable; import javax.persistence.MappedSuperclass; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java similarity index 56% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java index 7758440160..11fed92ee6 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/MappedSuperclassWithEntityWithIdClassTest.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.jpa.test.metagen.mappedsuperclass.idclass; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.idclass; import javax.persistence.EntityManagerFactory; import java.util.Arrays; @@ -12,18 +12,19 @@ import java.util.Arrays; import org.hibernate.jpa.test.TestingEntityManagerFactoryGenerator; import org.hibernate.jpa.AvailableSettings; -import org.junit.Test; - import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.hibernate.testing.orm.junit.BaseUnitTest; -import static org.junit.Assert.assertNotNull; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Alexis Bataille * @author Steve Ebersole */ -public class MappedSuperclassWithEntityWithIdClassTest extends BaseUnitTestCase { +@BaseUnitTest +public class MappedSuperclassWithEntityWithIdClassTest { @Test @TestForIssue( jiraKey = "HHH-5024" ) public void testStaticMetamodel() { @@ -33,11 +34,11 @@ public class MappedSuperclassWithEntityWithIdClassTest extends BaseUnitTestCase ); try { - assertNotNull( "'ProductAttribute_.value' should not be null)", ProductAttribute_.value ); - assertNotNull( "'ProductAttribute_.owner' should not be null)", ProductAttribute_.owner ); - assertNotNull( "'ProductAttribute_.key' should not be null)", ProductAttribute_.key ); + assertNotNull( ProductAttribute_.value, "'ProductAttribute_.value' should not be null)" ); + assertNotNull( ProductAttribute_.owner, "'ProductAttribute_.owner' should not be null)" ); + assertNotNull( ProductAttribute_.key, "'ProductAttribute_.key' should not be null)" ); - assertNotNull( "'AbstractAttribute_.value' should not be null)", AbstractAttribute_.value ); + assertNotNull( AbstractAttribute_.value, "'AbstractAttribute_.value' should not be null)" ); } finally { emf.close(); diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttribute.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttribute.java similarity index 93% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttribute.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttribute.java index a5fb93b968..106507e475 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttribute.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttribute.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.jpa.test.metagen.mappedsuperclass.idclass; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.idclass; import java.io.Serializable; import javax.persistence.Column; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttributeId.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttributeId.java similarity index 95% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttributeId.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttributeId.java index 113c4e28b9..39facc5545 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/idclass/ProductAttributeId.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/idclass/ProductAttributeId.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.jpa.test.metagen.mappedsuperclass.idclass; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.idclass; /** * @author Alexis Bataille diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/AbstractProduct.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/AbstractProduct.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/AbstractProduct.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/AbstractProduct.java index a2d95c3152..68e3ee0d30 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/AbstractProduct.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/AbstractProduct.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.jpa.test.metagen.mappedsuperclass.overridden; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.overridden; import javax.persistence.Access; import javax.persistence.AccessType; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java similarity index 64% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java index d3d4fed79d..ee669cdf34 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/MappedSuperclassWithOverriddenAttributeTest.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.jpa.test.metagen.mappedsuperclass.overridden; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.overridden; import java.util.Arrays; import javax.persistence.EntityManagerFactory; @@ -12,19 +12,20 @@ import javax.persistence.EntityManagerFactory; import org.hibernate.jpa.AvailableSettings; import org.hibernate.jpa.test.TestingEntityManagerFactoryGenerator; -import org.hibernate.testing.FailureExpected; import org.hibernate.testing.TestForIssue; -import org.hibernate.testing.junit4.BaseUnitTestCase; -import org.junit.Test; +import org.hibernate.testing.orm.junit.BaseUnitTest; +import org.hibernate.testing.orm.junit.FailureExpected; -import static org.junit.Assert.assertNotNull; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Oliver Breidenbach */ @TestForIssue(jiraKey = "HHH-11078") -public class MappedSuperclassWithOverriddenAttributeTest - extends BaseUnitTestCase { +@BaseUnitTest +public class MappedSuperclassWithOverriddenAttributeTest { @Test @FailureExpected(jiraKey = "HHH-11078") @@ -35,13 +36,13 @@ public class MappedSuperclassWithOverriddenAttributeTest ); try { assertNotNull( - "'Product1_.overridenName' should not be null)", - Product1_.overridenName + Product1_.overridenName, + "'Product1_.overridenName' should not be null)" ); assertNotNull( - "'Product2_.overridenName' should not be null)", - Product2_.overridenName + Product2_.overridenName, + "'Product2_.overridenName' should not be null)" ); // is null } finally { diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product1.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product1.java similarity index 92% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product1.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product1.java index 80038c24d0..5977b2697c 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product1.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product1.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.jpa.test.metagen.mappedsuperclass.overridden; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.overridden; import javax.persistence.Access; import javax.persistence.AccessType; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product2.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product2.java similarity index 91% rename from hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product2.java rename to hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product2.java index 571eb87f90..1adf7a4383 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metagen/mappedsuperclass/overridden/Product2.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/metagen/mappedsuperclass/overridden/Product2.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.jpa.test.metagen.mappedsuperclass.overridden; +package org.hibernate.orm.test.jpa.metagen.mappedsuperclass.overridden; import javax.persistence.Access; import javax.persistence.AccessType; diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Hbm2ddlCreateOnlyTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Hbm2ddlCreateOnlyTest.java index 027b5e9c3d..ee8b3a6653 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Hbm2ddlCreateOnlyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/Hbm2ddlCreateOnlyTest.java @@ -14,7 +14,7 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jpa.boot.spi.Bootstrap; import org.hibernate.jpa.test.PersistenceUnitDescriptorAdapter; -import org.hibernate.jpa.test.mapping.ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity; +import org.hibernate.orm.test.jpa.mapping.ColumnWithExplicitReferenceToPrimaryTableTest.AnEntity; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.logger.LoggerInspectionRule; import org.hibernate.testing.logger.Triggerable; diff --git a/hibernate-core/src/test/resources/org/hibernate/jpa/test/mapping/orm.xml b/hibernate-core/src/test/resources/org/hibernate/orm/test/jpa/mapping/orm.xml similarity index 100% rename from hibernate-core/src/test/resources/org/hibernate/jpa/test/mapping/orm.xml rename to hibernate-core/src/test/resources/org/hibernate/orm/test/jpa/mapping/orm.xml