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 306b04a7a0..1f8ff5b248 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 @@ -99,8 +99,8 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa @Access(AccessType.FIELD) public static class MarketBidGroup { @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE") - @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketBidGroup", allocationSize = 10000) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE_2") + @TableGenerator(name = "ID_TABLE_2", pkColumnValue = "MarketBidGroup", allocationSize = 10000) private Long id; @OneToMany(mappedBy = "group") @@ -115,8 +115,8 @@ public class InsertOrderingWithCascadeOnPersist extends BaseCoreFunctionalTestCa @Access(AccessType.FIELD) public static class MarketResult { @Id - @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE") - @TableGenerator(name = "ID_TABLE", pkColumnValue = "MarketResult", allocationSize = 10000) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_TABLE_3") + @TableGenerator(name = "ID_TABLE_3", 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/compliance/tck2_2/TableGeneratorMultipleDefinitionTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/TableGeneratorMultipleDefinitionTest.java new file mode 100644 index 0000000000..6b01bcdb5a --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/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.compliance.tck2_2; + +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/compliance/tck2_2/TableGeneratorVisibilityTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/TableGeneratorVisibilityTest.java new file mode 100644 index 0000000000..f38d6dde49 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/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.compliance.tck2_2; + +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; + } +}