use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testImplicitSequenceGenerator.
@Test
public void testImplicitSequenceGenerator() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false").build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ImplicitSequenceGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ImplicitSequenceGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
// PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME == false indicates that the legacy
// default (hibernate_sequence) should be used
assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is("hibernate_sequence"));
// the JPA defaults since they were not defined
assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(1));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(50));
}
use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.
the class GeneratedValueTests method testExplicitSequenceGeneratorImplicitName.
@Test
public void testExplicitSequenceGeneratorImplicitName() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, "false").build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitSequenceGeneratorImplicitNameEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitSequenceGeneratorImplicitNameEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
// all the JPA defaults since they were not defined
assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is(SequenceStyleGenerator.DEF_SEQUENCE_NAME));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(100));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(500));
}
use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.
the class NewGeneratorMappingsTest method testSequencePerEntity.
@Test
@TestForIssue(jiraKey = "HHH-6790")
public void testSequencePerEntity() {
// Checking first entity.
EntityPersister persister = sessionFactory().getEntityPersister(DedicatedSequenceEntity1.class.getName());
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue(SequenceStyleGenerator.class.isInstance(generator));
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(StringHelper.unqualifyEntityName(DedicatedSequenceEntity1.class.getName()) + DedicatedSequenceEntity1.SEQUENCE_SUFFIX, seqGenerator.getDatabaseStructure().getName());
// Checking second entity.
persister = sessionFactory().getEntityPersister(DedicatedSequenceEntity2.class.getName());
generator = persister.getIdentifierGenerator();
assertTrue(SequenceStyleGenerator.class.isInstance(generator));
seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(DedicatedSequenceEntity2.ENTITY_NAME + DedicatedSequenceEntity1.SEQUENCE_SUFFIX, seqGenerator.getDatabaseStructure().getName());
}
use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.
the class NewGeneratorMappingsTest method testMinimalSequenceEntity.
@Test
public void testMinimalSequenceEntity() {
final EntityPersister persister = sessionFactory().getEntityPersister(MinimalSequenceEntity.class.getName());
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue(SequenceStyleGenerator.class.isInstance(generator));
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(MinimalSequenceEntity.SEQ_NAME, seqGenerator.getDatabaseStructure().getName());
// 1 is the annotation default
assertEquals(1, seqGenerator.getDatabaseStructure().getInitialValue());
// 50 is the annotation default
assertEquals(50, seqGenerator.getDatabaseStructure().getIncrementSize());
assertFalse(NoopOptimizer.class.isInstance(seqGenerator.getOptimizer()));
}
use of org.hibernate.id.enhanced.SequenceStyleGenerator in project hibernate-orm by hibernate.
the class NewGeneratorMappingsTest method testAutoEntity.
@Test
public void testAutoEntity() {
final EntityPersister persister = sessionFactory().getEntityPersister(AutoEntity.class.getName());
IdentifierGenerator generator = persister.getIdentifierGenerator();
assertTrue(SequenceStyleGenerator.class.isInstance(generator));
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
assertEquals(SequenceStyleGenerator.DEF_SEQUENCE_NAME, seqGenerator.getDatabaseStructure().getName());
assertEquals(SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue());
assertEquals(SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize());
}
Aggregations