public class TableGenerator
extends org.hibernate.id.enhanced.TableGenerator
TableGenerator
for the sole purpose to
allow overriding the TableGenerator.OPT_PARAM
and
TableGenerator.INITIAL_PARAM
for the testing environment
(in principle you can override any of the TableGenerator parameters).
Test data may not always contain the hibernate sequences table which often leads to problems
with existing primary key values when inserting new entities. This especially occurs when
running test in a suite.
To circumvent these problems you can set a global override for the high initial parameter which
is far beyond any id ever used in test data sets.
You may want to set this in your testing application context, eg:
<bean id="tableGeneratorGlobalOverride" class="eu.etaxonomy.cdm.persistence.hibernate.TableGeneratorGlobalOverride"> <property name="properties"> <props> <!-- globally overriding id generation settings see: eu.etaxonomy.cdm.persistence.hibernate.TableGenerator --> <prop key="optimizer">none</prop> <prop key="initial_value">1000</prop> </props> </property> </bean>If you set the optimizer to "none", hibernate will always query the database for each new id. You must tell spring to instantiate the ... before the session factory:
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" depends-on="tableGeneratorGlobalOverride"> ...
CONFIG_PREFER_SEGMENT_PER_ENTITY, DEF_SEGMENT_COLUMN, DEF_SEGMENT_LENGTH, DEF_SEGMENT_VALUE, DEF_TABLE, DEF_VALUE_COLUMN, DEFAULT_INCREMENT_SIZE, DEFAULT_INITIAL_VALUE, INCREMENT_PARAM, INITIAL_PARAM, OPT_PARAM, SEGMENT_COLUMN_PARAM, SEGMENT_LENGTH_PARAM, SEGMENT_VALUE_PARAM, TABLE_PARAM, VALUE_COLUMN_PARAM
Constructor and Description |
---|
TableGenerator() |
Modifier and Type | Method and Description |
---|---|
void |
configure(org.hibernate.type.Type type,
java.util.Properties params,
org.hibernate.service.ServiceRegistry serviceRegistry) |
buildInsertQuery, buildSelectQuery, buildUpdateQuery, determineDefaultSegmentValue, determineGeneratorTableName, determineIncrementSize, determineInitialValue, determineSegmentColumnName, determineSegmentColumnSize, determineSegmentValue, determineValueColumnName, generate, generatorKey, getIdentifierType, getIncrementSize, getInitialValue, getOptimizer, getSegmentColumnName, getSegmentValue, getSegmentValueLength, getTableAccessCount, getTableName, getValueColumnName, registerExportables, sqlCreateStrings, sqlDropStrings
public void configure(org.hibernate.type.Type type, java.util.Properties params, org.hibernate.service.ServiceRegistry serviceRegistry) throws org.hibernate.MappingException
configure
in interface org.hibernate.id.Configurable
configure
in class org.hibernate.id.enhanced.TableGenerator
org.hibernate.MappingException
Copyright © 2007-2020 EDIT. All Rights Reserved.