HHH-12157 - Add test for issue

(cherry picked from commit f40a6cc0f8fd0ccb03387beb5dac9d9bde846c4d)
This commit is contained in:
Andrea Boriero 2017-12-11 14:59:05 +00:00
parent 8acebf7df8
commit 7c0f8474f5
12 changed files with 172 additions and 27 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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")

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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 = {

View File

@ -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;
}

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}