From 7c0f8474f5dfe6ad1511d15ebceb79fa30d531c6 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 11 Dec 2017 14:59:05 +0000 Subject: [PATCH] HHH-12157 - Add test for issue (cherry picked from commit f40a6cc0f8fd0ccb03387beb5dac9d9bde846c4d) --- ...thTransientNonCascadedAssociationTest.java | 4 +- .../mapped_by_id/LoadGraphFindByIdTest.java | 1 + .../annotations/onetoone/OwnerAddress.java | 4 +- .../JoinedInheritanceWithOneToManyTest.java | 4 - ...ithBidirectionalOneToManyFlushProblem.java | 12 +-- .../InsertOrderingWithCascadeOnPersist.java | 6 +- ...ertOrderingWithJoinedTableInheritance.java | 4 +- ...gWithJoinedTableMultiLevelInheritance.java | 8 +- ...ertOrderingWithSingleTableInheritance.java | 4 +- ...tOrderingWithTablePerClassInheritance.java | 4 +- .../TableGeneratorMultipleDefinitionTest.java | 63 ++++++++++++++ .../TableGeneratorVisibilityTest.java | 85 +++++++++++++++++++ 12 files changed, 172 insertions(+), 27 deletions(-) create mode 100644 hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorMultipleDefinitionTest.java create mode 100644 hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorVisibilityTest.java diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/cascade/MergeWithTransientNonCascadedAssociationTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/cascade/MergeWithTransientNonCascadedAssociationTest.java index dbc3d15dc4..b42727698b 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/cascade/MergeWithTransientNonCascadedAssociationTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/cascade/MergeWithTransientNonCascadedAssociationTest.java @@ -79,8 +79,8 @@ public class MergeWithTransientNonCascadedAssociationTest extends BaseEntityMana @Entity( name = "Address" ) public static class Address { @Id - @GeneratedValue( generator = "increment" ) - @GenericGenerator( name = "increment", strategy = "increment" ) + @GeneratedValue( generator = "increment_1" ) + @GenericGenerator( name = "increment_1", strategy = "increment" ) private Integer id; } } diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/mapped_by_id/LoadGraphFindByIdTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/mapped_by_id/LoadGraphFindByIdTest.java index 2f160233d7..c6a50321dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/mapped_by_id/LoadGraphFindByIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/graphs/mapped_by_id/LoadGraphFindByIdTest.java @@ -12,6 +12,7 @@ import javax.persistence.Entity; import javax.persistence.EntityGraph; import javax.persistence.EntityManager; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.MapsId; import javax.persistence.OneToOne; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java index f401fac3a6..0af8420a9e 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OwnerAddress.java @@ -20,8 +20,8 @@ import org.hibernate.annotations.Parameter; */ @Entity public class OwnerAddress { - @Id @GeneratedValue(generator = "fk") - @GenericGenerator(strategy = "foreign", name = "fk", parameters = @Parameter(name="property", value="owner")) + @Id @GeneratedValue(generator = "fk_1") + @GenericGenerator(strategy = "foreign", name = "fk_1", parameters = @Parameter(name="property", value="owner")) private Integer id; @OneToOne(mappedBy="address") diff --git a/hibernate-core/src/test/java/org/hibernate/test/inheritance/relationship/JoinedInheritanceWithOneToManyTest.java b/hibernate-core/src/test/java/org/hibernate/test/inheritance/relationship/JoinedInheritanceWithOneToManyTest.java index 7a708b5ece..78173c012a 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/inheritance/relationship/JoinedInheritanceWithOneToManyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/inheritance/relationship/JoinedInheritanceWithOneToManyTest.java @@ -141,12 +141,8 @@ public class JoinedInheritanceWithOneToManyTest extends BaseNonConfigCoreFunctio @Entity(name = "BuildingListEntry") @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "TB_BUILDING_LIST_ENTRY") - @SequenceGenerator(name = "seq", - sequenceName = "sq_building_list_entry_id", - allocationSize = 1) public static class BuildingListEntry extends DBObject implements Serializable { - @Column protected String comments; diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToManyFlushProblem.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToManyFlushProblem.java index f1c7fe9ba0..3bc04ea866 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToManyFlushProblem.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithBidirectionalOneToManyFlushProblem.java @@ -160,11 +160,11 @@ public class InsertOrderingWithBidirectionalOneToManyFlushProblem @Column(nullable = false) @GeneratedValue( strategy = SEQUENCE, - generator = "ID" + generator = "ID_2" ) @Id @SequenceGenerator( - name = "ID", + name = "ID_2", sequenceName = "BOTTOM2_SEQ" ) private Long id; @@ -179,11 +179,11 @@ public class InsertOrderingWithBidirectionalOneToManyFlushProblem @Column(nullable = false) @GeneratedValue( strategy = SEQUENCE, - generator = "ID" + generator = "ID_3" ) @Id @SequenceGenerator( - name = "ID", + name = "ID_3", sequenceName = "MIDDLE_SEQ" ) private Long id; @@ -220,11 +220,11 @@ public class InsertOrderingWithBidirectionalOneToManyFlushProblem @Column(nullable = false) @GeneratedValue( strategy = SEQUENCE, - generator = "ID" + generator = "ID_4" ) @Id @SequenceGenerator( - name = "ID", + name = "ID_4", sequenceName = "TOP_SEQ" ) private Long id; diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java index 196964ca76..928d5ae627 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithCascadeOnPersist.java @@ -80,7 +80,7 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa public static class MarketBid { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBid") - @TableGenerator(name = "MarketBid", pkColumnValue = "MarketBid", allocationSize = 10000) + @TableGenerator(name = "MarketBid", table = "MARKET_BID", pkColumnValue = "MarketBid", allocationSize = 10000) private Long id; @ManyToOne(optional = false, cascade = CascadeType.PERSIST) @@ -100,7 +100,7 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa public static class MarketBidGroup { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketBidGroup") - @TableGenerator(name = "MarketBidGroup", pkColumnValue = "MarketBidGroup", allocationSize = 10000) + @TableGenerator(name = "MarketBidGroup", table = "MARKET_BID", pkColumnValue = "MarketBidGroup", allocationSize = 10000) private Long id; @OneToMany(mappedBy = "group") @@ -116,7 +116,7 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa public static class MarketResult { @Id @GeneratedValue(strategy = GenerationType.TABLE, generator = "MarketResult") - @TableGenerator(name = "MarketResult", pkColumnValue = "MarketResult", allocationSize = 10000) + @TableGenerator(name = "MarketResult", table = "MARKET_BID", pkColumnValue = "MarketResult", allocationSize = 10000) private Long id; @ManyToOne(optional = false) diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java index aafd95d680..0feeb2f80f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableInheritance.java @@ -126,8 +126,8 @@ public class InsertOrderingWithJoinedTableInheritance public static class Person { @Id @Column(name = "ID", nullable = false) - @SequenceGenerator(name = "ID", sequenceName = "PERSON_SEQ") - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") + @SequenceGenerator(name = "ID_2", sequenceName = "PERSON_SEQ") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_2") private Long id; @OneToMany(orphanRemoval = true, cascade = { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java index a238e8b590..b081bf72b2 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithJoinedTableMultiLevelInheritance.java @@ -133,8 +133,8 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance public static class Office { @Id @Column(name = "ID", nullable = false) - @SequenceGenerator(name = "ID", sequenceName = "ADDRESS_SEQ") - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") + @SequenceGenerator(name = "ID_2", sequenceName = "ADDRESS_SEQ") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_2") private Long id; } @@ -145,8 +145,8 @@ public class InsertOrderingWithJoinedTableMultiLevelInheritance public static class Person { @Id @Column(name = "ID", nullable = false) - @SequenceGenerator(name = "ID", sequenceName = "PERSON_SEQ") - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") + @SequenceGenerator(name = "ID_3", sequenceName = "PERSON_SEQ") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_3") private Long id; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java index 20b0e240cb..544aa17d88 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithSingleTableInheritance.java @@ -127,8 +127,8 @@ public class InsertOrderingWithSingleTableInheritance public static class Person { @Id @Column(name = "ID", nullable = false) - @SequenceGenerator(name = "ID", sequenceName = "PERSON_SEQ") - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") + @SequenceGenerator(name = "ID_2", sequenceName = "PERSON_SEQ") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_2") private Long id; @OneToMany(orphanRemoval = true, cascade = { diff --git a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java index 73b4da879e..b2f21baed6 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java +++ b/hibernate-core/src/test/java/org/hibernate/test/insertordering/InsertOrderingWithTablePerClassInheritance.java @@ -127,8 +127,8 @@ public class InsertOrderingWithTablePerClassInheritance public static class Person { @Id @Column(name = "ID", nullable = false) - @SequenceGenerator(name = "ID", sequenceName = "PERSON_SEQ") - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID") + @SequenceGenerator(name = "ID_2", sequenceName = "PERSON_SEQ") + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_2") private Long id; @OneToMany(orphanRemoval = true, cascade = { diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorMultipleDefinitionTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorMultipleDefinitionTest.java new file mode 100644 index 0000000000..bcdb734e34 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorMultipleDefinitionTest.java @@ -0,0 +1,63 @@ +/* + * 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.jpa.idgenerator; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.TableGenerator; + +import org.hibernate.boot.MetadataSources; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseUnitTestCase; +import org.junit.Test; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-12157") +public class TableGeneratorMultipleDefinitionTest extends BaseUnitTestCase { + + @Test(expected = IllegalArgumentException.class) + public void testDuplicateGeneratorNamesDefinition() { + new MetadataSources().addAnnotatedClass( TestEntity1.class ) + .addAnnotatedClass( TestEntity2.class ) + .buildMetadata() + .buildSessionFactory().close(); + + } + + @Entity(name = "TestEntity1") + @TableGenerator( + name = "table-generator", + table = "table_identifier", + pkColumnName = "identifier", + valueColumnName = "value", + allocationSize = 5 + ) + public static class TestEntity1 { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator") + public long id; + } + + @Entity(name = "TestEntity2") + @TableGenerator( + name = "table-generator", + table = "table_identifier_2", + pkColumnName = "identifier", + valueColumnName = "value", + allocationSize = 5 + ) + public static class TestEntity2 { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator") + public long id; + } +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorVisibilityTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorVisibilityTest.java new file mode 100644 index 0000000000..f9e14f766b --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/idgenerator/TableGeneratorVisibilityTest.java @@ -0,0 +1,85 @@ +/* + * 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.jpa.idgenerator; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.TableGenerator; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.hibernate.testing.transaction.TransactionUtil; +import org.junit.Test; + +/** + * @author Andrea Boriero + */ +@TestForIssue(jiraKey = "HHH-12157") +public class TableGeneratorVisibilityTest extends BaseCoreFunctionalTestCase { + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + TestEntity1.class, + TestEntity2.class, + TestEntity3.class + }; + } + + @Test + public void testGeneratorIsVisible() { + TransactionUtil.doInHibernate( this::sessionFactory, session -> { + session.persist( new TestEntity1() ); + } ); + + TransactionUtil.doInHibernate( this::sessionFactory, session -> { + session.persist( new TestEntity2() ); + } ); + + TransactionUtil.doInHibernate( this::sessionFactory, session -> { + session.persist( new TestEntity3() ); + } ); + } + + @Entity(name = "TestEntity1") + + public static class TestEntity1 { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator-2") + public long id; + } + + @Entity(name = "TestEntity2") + public static class TestEntity2 { + @Id + @GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator") + public long id; + } + + @Entity(name = "TestEntity3") + @TableGenerator( + name = "table-generator", + table = "table_identifier", + pkColumnName = "identifier", + valueColumnName = "value", + allocationSize = 5 + ) + public static class TestEntity3 { + @Id + @TableGenerator( + name = "table-generator-2", + table = "table_identifier_2", + pkColumnName = "identifier", + valueColumnName = "value", + allocationSize = 5 + ) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator") + public long id; + } +}