HHH-14495 Use table name, rather than entity name, as base for per-entity implicit sequence naming
This commit is contained in:
parent
34f0b08c24
commit
87258af3f9
|
@ -323,7 +323,7 @@ public abstract class SimpleValue implements KeyValue {
|
|||
if ( rootClass != null ) {
|
||||
params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
|
||||
params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName() );
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, rootClass.getJpaEntityName() );
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, getTable().getName() );
|
||||
|
||||
final StringBuilder tables = new StringBuilder();
|
||||
final Iterator<Table> itr = rootClass.getIdentityTables().iterator();
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* 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.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
|
||||
/**
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@Entity
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public abstract class AbstractTPCAutoEntity {
|
||||
private Long id;
|
||||
|
||||
@Id @GeneratedValue
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long long1) {
|
||||
id = long1;
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ import org.hibernate.id.enhanced.NoopOptimizer;
|
|||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
|
@ -40,7 +39,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
AutoEntity.class,
|
||||
MinimalTableEntity.class,
|
||||
DedicatedSequenceEntity1.class,
|
||||
DedicatedSequenceEntity2.class
|
||||
DedicatedSequenceEntity2.class,
|
||||
AbstractTPCAutoEntity.class,
|
||||
TPCAutoEntity1.class
|
||||
},
|
||||
annotatedPackageNames = {
|
||||
"org.hibernate.orm.test.annotations.id.generationmappings"
|
||||
|
@ -89,6 +90,17 @@ public class NewGeneratorMappingsTest {
|
|||
assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTablePerClassAutoEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( AbstractTPCAutoEntity.class.getName() );
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals( "AbstractTPCAutoEntity_SEQ", seqGenerator.getDatabaseStructure().getName() );
|
||||
assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue() );
|
||||
assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMinimalTableEntity(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( MinimalTableEntity.class.getName() );
|
||||
|
@ -115,7 +127,7 @@ public class NewGeneratorMappingsTest {
|
|||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals(
|
||||
StringHelper.unqualifyEntityName( DedicatedSequenceEntity1.class.getName() ) + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
|
||||
"DEDICATED_SEQ_TBL1" + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
|
||||
seqGenerator.getDatabaseStructure().getName()
|
||||
);
|
||||
|
||||
|
@ -125,7 +137,7 @@ public class NewGeneratorMappingsTest {
|
|||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals(
|
||||
DedicatedSequenceEntity2.ENTITY_NAME + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
|
||||
"DEDICATED_SEQ_TBL2" + DedicatedSequenceEntity1.SEQUENCE_SUFFIX,
|
||||
seqGenerator.getDatabaseStructure().getName()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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.orm.test.annotations.id.generationmappings;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
/**
|
||||
* @author Christian Beikov
|
||||
*/
|
||||
@Entity
|
||||
public class TPCAutoEntity1 extends AbstractTPCAutoEntity {
|
||||
private String name1;
|
||||
|
||||
public String getName1() {
|
||||
return name1;
|
||||
}
|
||||
|
||||
public void setName1(String name1) {
|
||||
this.name1 = name1;
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ public class AutoGenerationTypeTests {
|
|||
final DatabaseStructure database1Structure = entityIdGenerator.getDatabaseStructure();
|
||||
|
||||
// implicit name : `${entity-name}_seq`
|
||||
assertThat( database1Structure.getName(), equalToIgnoringCase( "Entity1_seq" ) );
|
||||
assertThat( database1Structure.getName(), equalToIgnoringCase( "tbl_1_SEQ" ) );
|
||||
assertThat( database1Structure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class BasicSequenceTest {
|
|||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertEquals( overriddenEntityName + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX, generator.getDatabaseStructure().getName() );
|
||||
assertEquals( "ID_SEQ_BSC_ENTITY" + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX, generator.getDatabaseStructure().getName() );
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
|
|
Loading…
Reference in New Issue