Search in sources :

Example 11 with IdentifierGenerator

use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.

the class DefaultIdentifierGeneratorFactory method createIdentifierGenerator.

@Override
public IdentifierGenerator createIdentifierGenerator(String strategy, Type type, Properties config) {
    try {
        Class clazz = getIdentifierGeneratorClass(strategy);
        IdentifierGenerator identifierGenerator = (IdentifierGenerator) clazz.newInstance();
        if (identifierGenerator instanceof Configurable) {
            ((Configurable) identifierGenerator).configure(type, config, serviceRegistry);
        }
        return identifierGenerator;
    } catch (Exception e) {
        final String entityName = config.getProperty(IdentifierGenerator.ENTITY_NAME);
        throw new MappingException(String.format("Could not instantiate id generator [entity-name=%s]", entityName), e);
    }
}
Also used : Configurable(org.hibernate.id.Configurable) MappingException(org.hibernate.MappingException) ClassLoadingException(org.hibernate.boot.registry.classloading.spi.ClassLoadingException) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) MappingException(org.hibernate.MappingException)

Example 12 with IdentifierGenerator

use of org.hibernate.id.IdentifierGenerator in project hibernate-orm by hibernate.

the class MonotonicRevisionNumberTest method testOracleSequenceOrder.

@Test
public void testOracleSequenceOrder() {
    EntityPersister persister = sessionFactory().getEntityPersister(SequenceIdRevisionEntity.class.getName());
    IdentifierGenerator generator = persister.getIdentifierGenerator();
    Assert.assertTrue(OrderedSequenceGenerator.class.isInstance(generator));
    OrderedSequenceGenerator seqGenerator = (OrderedSequenceGenerator) generator;
    Assert.assertTrue("Oracle sequence needs to be ordered in RAC environment.", seqGenerator.sqlCreateStrings(getDialect())[0].toLowerCase().endsWith(" order"));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) OrderedSequenceGenerator(org.hibernate.envers.enhanced.OrderedSequenceGenerator) IdentifierGenerator(org.hibernate.id.IdentifierGenerator) Test(org.junit.Test)

Aggregations

IdentifierGenerator (org.hibernate.id.IdentifierGenerator)12 EntityPersister (org.hibernate.persister.entity.EntityPersister)8 Test (org.junit.Test)8 SequenceStyleGenerator (org.hibernate.id.enhanced.SequenceStyleGenerator)5 BulkInsertionCapableIdentifierGenerator (org.hibernate.id.BulkInsertionCapableIdentifierGenerator)2 NoopOptimizer (org.hibernate.id.enhanced.NoopOptimizer)2 AST (antlr.collections.AST)1 Iterator (java.util.Iterator)1 MappingException (org.hibernate.MappingException)1 QueryException (org.hibernate.QueryException)1 Session (org.hibernate.Session)1 SessionFactory (org.hibernate.SessionFactory)1 Metadata (org.hibernate.boot.Metadata)1 MetadataSources (org.hibernate.boot.MetadataSources)1 MetadataImpl (org.hibernate.boot.internal.MetadataImpl)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)1 ClassLoadingException (org.hibernate.boot.registry.classloading.spi.ClassLoadingException)1 OrderedSequenceGenerator (org.hibernate.envers.enhanced.OrderedSequenceGenerator)1 SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)1