Example usage for org.hibernate.id.enhanced SequenceStyleGenerator SequenceStyleGenerator

List of usage examples for org.hibernate.id.enhanced SequenceStyleGenerator SequenceStyleGenerator

Introduction

In this page you can find the example usage for org.hibernate.id.enhanced SequenceStyleGenerator SequenceStyleGenerator.

Prototype

SequenceStyleGenerator

Source Link

Usage

From source file:net.sf.beanlib.hibernate4.Hibernate4SequenceGenerator.java

License:Apache License

/** Returns the identifier generator created for the specified sequence and session. */
private static IdentifierGenerator createIdentifierGenerator(String sequenceName, Session session) {
    SessionFactory sessionFactory = session.getSessionFactory();

    if (!(sessionFactory instanceof SessionFactoryImpl)) {
        throw new IllegalStateException("Not yet know how to handle the session factory of the given session!");
    }/*from w w w .  j a  v  a2s  .c  om*/
    SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) sessionFactory;
    //        Dialect dialect = sessionFactoryImpl.getDialect();
    ServiceRegistry registry = sessionFactoryImpl.getServiceRegistry();

    Properties params = new Properties();
    params.setProperty("sequence", sequenceName);

    SequenceStyleGenerator sequenceStyleGenerator = new SequenceStyleGenerator();
    sequenceStyleGenerator.configure(LongType.INSTANCE, params, (ServiceRegistry) registry);

    //        SequenceGenerator sequenceGenerator = new SequenceGenerator();
    //        sequenceGenerator.configure(LongType.INSTANCE, params, dialect);

    return sequenceStyleGenerator;
}