Example usage for org.hibernate.id.enhanced TableGenerator INCREMENT_PARAM

List of usage examples for org.hibernate.id.enhanced TableGenerator INCREMENT_PARAM

Introduction

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

Prototype

String INCREMENT_PARAM

To view the source code for org.hibernate.id.enhanced TableGenerator INCREMENT_PARAM.

Click Source Link

Document

Indicates the increment size to use.

Usage

From source file:com.sapienter.jbilling.server.util.db.HibernateIdGenerator.java

License:Open Source License

/**
 * Constructs a new ID generator for the given segment. If the segment does
 * not exist in the sequence table, it will be created with the newly generated
 * id values starting from zero.//from   w w  w .j  a v  a  2s.c o  m
 *      *
 * @param segmentValue jbilling sequence name (value of the 'name' column)
 */
public HibernateIdGenerator(String segmentValue) {
    /*
    I consider this code to be a "horrific sin against nature and a total affront to the programming gods",
    but it's the only way to gain access to Hibernates IdentifierGenerator framework. Future versions
    of Hibernate may change the underlying implementation which will break this code.
     */
    Properties configuration = new Properties();
    configuration.setProperty(TableGenerator.TABLE_PARAM, "jbilling_seqs");
    configuration.setProperty(TableGenerator.SEGMENT_COLUMN_PARAM, "name");
    configuration.setProperty(TableGenerator.SEGMENT_VALUE_PARAM, segmentValue);
    configuration.setProperty(TableGenerator.VALUE_COLUMN_PARAM, "next_id");
    configuration.setProperty(TableGenerator.INCREMENT_PARAM, "100");

    sessionFactory = ((SessionFactory) Context.getBean(Context.Name.HIBERNATE_SESSION));
    generator = IdentifierGeneratorFactory.create("org.hibernate.id.enhanced.TableGenerator", new IntegerType(),
            configuration, ((SessionFactoryImpl) sessionFactory).getDialect());
}