mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-08 02:40:24 +00:00
HHH-14506 - IdentifierGenerator changes
- HHH-14491 - Apply default allocation/increment size for @GeneratedValue(AUTO) - HHH-14492 - Prefer sequence-per-entity (hierarchy) by default - HHH-14497 - Drop `hibernate.id.new_generator_mappings` & `hibernate.model.generator_name_as_sequence_name` - enabled existing tests and convert to JUnit5
This commit is contained in:
parent
d963acf443
commit
31b1627baa
@ -210,9 +210,6 @@ xjc {
|
||||
//sourceSets.main.sourceGeneratorsTask.dependsOn antlr
|
||||
tasks.compile.dependsOn antlr
|
||||
|
||||
// todo (6.0) : remove this once we get 6.0 stable-ish
|
||||
tasks.withType( JavaCompile ).forEach({ JavaCompile c -> c.options.compilerArgs += ["-Xmaxerrs", "4999"]})
|
||||
|
||||
task copyBundleResources (type: Copy) {
|
||||
ext {
|
||||
bundlesTargetDir = file( "${buildDir}/bundles" )
|
||||
|
@ -96,6 +96,12 @@ public static boolean isQuoted(String name) {
|
||||
|| ( name.startsWith( "\"" ) && name.endsWith( "\"" ) );
|
||||
}
|
||||
|
||||
public static String unQuote(String name) {
|
||||
assert isQuoted( name );
|
||||
|
||||
return name.substring( 1, name.length() - 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an identifier instance.
|
||||
*
|
||||
|
@ -2031,7 +2031,11 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
||||
* The default value is `true` meaning that {@link GeneratedValue#generator()} will be used as the
|
||||
* sequence/table name by default. Users migrating from earlier versions using the legacy
|
||||
* `hibernate_sequence` name should disable this setting.
|
||||
*
|
||||
* @deprecated As of 6.0 with no replacement - `hibernate_sequence` as a real, implicit exportable name
|
||||
* is no longer supported. No effect
|
||||
*/
|
||||
@Deprecated
|
||||
String PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME = "hibernate.model.generator_name_as_sequence_name";
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.id;
|
||||
|
||||
import org.hibernate.boot.model.relational.ExportableProducer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.id.enhanced.StandardOptimizerDescriptor;
|
||||
|
||||
/**
|
||||
* Commonality between sequence-based and table-based generators
|
||||
*/
|
||||
public interface OptimizableGenerator extends IdentifierGenerator, ExportableProducer {
|
||||
/**
|
||||
* If an explicit sequence/table name is not configured,
|
||||
*/
|
||||
String IMPLICIT_NAME_BASE = "implicit_name_base";
|
||||
|
||||
/**
|
||||
* Indicates the initial value to use. The default value is {@link #DEFAULT_INITIAL_VALUE}
|
||||
*/
|
||||
String INITIAL_PARAM = "initial_value";
|
||||
|
||||
/**
|
||||
* The default value for {@link #INITIAL_PARAM}
|
||||
*/
|
||||
int DEFAULT_INITIAL_VALUE = 1;
|
||||
|
||||
/**
|
||||
* Indicates the increment size to use. The default value is {@link #DEFAULT_INCREMENT_SIZE}
|
||||
*/
|
||||
String INCREMENT_PARAM = "increment_size";
|
||||
|
||||
/**
|
||||
* The default value for {@link #INCREMENT_PARAM}
|
||||
*/
|
||||
int DEFAULT_INCREMENT_SIZE = 50;
|
||||
|
||||
/**
|
||||
* Indicates the optimizer to use, either naming a {@link Optimizer} implementation class or naming
|
||||
* a {@link StandardOptimizerDescriptor} by name
|
||||
*
|
||||
* NOTE : has precedence over {@link #INCREMENT_PARAM}
|
||||
*/
|
||||
String OPT_PARAM = "optimizer";
|
||||
}
|
@ -22,7 +22,11 @@
|
||||
* @see IdentifierGenerator
|
||||
* @see Configurable
|
||||
*/
|
||||
public interface PersistentIdentifierGenerator extends IdentifierGenerator, ExportableProducer {
|
||||
public interface PersistentIdentifierGenerator extends OptimizableGenerator {
|
||||
/**
|
||||
* The configuration parameter holding the catalog name
|
||||
*/
|
||||
String CATALOG = "catalog";
|
||||
|
||||
/**
|
||||
* The configuration parameter holding the schema name
|
||||
@ -47,11 +51,6 @@ public interface PersistentIdentifierGenerator extends IdentifierGenerator, Expo
|
||||
*/
|
||||
String PK = "target_column";
|
||||
|
||||
/**
|
||||
* The configuration parameter holding the catalog name
|
||||
*/
|
||||
String CATALOG = "catalog";
|
||||
|
||||
/**
|
||||
* The key under which to find the {@link org.hibernate.boot.model.naming.ObjectNameNormalizer} in the config param map.
|
||||
*/
|
||||
|
@ -18,7 +18,6 @@
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
|
||||
@ -41,12 +40,6 @@
|
||||
* a sequence. These variations are encapsulated by the {@link DatabaseStructure}
|
||||
* interface internally.
|
||||
* <p/>
|
||||
* <b>NOTE</b> that by default we utilize a single database sequence for all
|
||||
* generators. The configuration parameter {@link #CONFIG_PREFER_SEQUENCE_PER_ENTITY}
|
||||
* can be used to create dedicated sequence for each entity based on its name.
|
||||
* Sequence suffix can be controlled with {@link #CONFIG_SEQUENCE_PER_ENTITY_SUFFIX}
|
||||
* option.
|
||||
* <p/>
|
||||
* General configuration parameters:
|
||||
* <table>
|
||||
* <tr>
|
||||
@ -110,49 +103,21 @@ public class SequenceStyleGenerator
|
||||
// general purpose parameters ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
/**
|
||||
* Indicates the name of the sequence (or table) to use. The default value is {@link #DEF_SEQUENCE_NAME},
|
||||
* although {@link #CONFIG_PREFER_SEQUENCE_PER_ENTITY} effects the default as well.
|
||||
* Indicates the name of the sequence (or table) to use. The implicit value is
|
||||
* based on the entity / collection-role name
|
||||
*/
|
||||
public static final String SEQUENCE_PARAM = "sequence_name";
|
||||
|
||||
/**
|
||||
* The default value for {@link #SEQUENCE_PARAM}, in the absence of any {@link #CONFIG_PREFER_SEQUENCE_PER_ENTITY}
|
||||
* setting.
|
||||
* @deprecated As of 6.0 with no replacement - `hibernate_sequence` as a real, implicit exportable name
|
||||
* is no longer supported. No effect
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String DEF_SEQUENCE_NAME = "hibernate_sequence";
|
||||
|
||||
/**
|
||||
* Indicates the initial value to use. The default value is {@link #DEFAULT_INITIAL_VALUE}
|
||||
* Specifies the suffix to use for an implicit sequence name - appended to the entity-name / collection-role
|
||||
*/
|
||||
public static final String INITIAL_PARAM = "initial_value";
|
||||
|
||||
/**
|
||||
* The default value for {@link #INITIAL_PARAM}
|
||||
*/
|
||||
public static final int DEFAULT_INITIAL_VALUE = 1;
|
||||
|
||||
/**
|
||||
* Indicates the increment size to use. The default value is {@link #DEFAULT_INCREMENT_SIZE}
|
||||
*/
|
||||
public static final String INCREMENT_PARAM = "increment_size";
|
||||
|
||||
/**
|
||||
* The default value for {@link #INCREMENT_PARAM}
|
||||
*/
|
||||
public static final int DEFAULT_INCREMENT_SIZE = 1;
|
||||
|
||||
/**
|
||||
* Used to create dedicated sequence for each entity based on the entity name. Sequence suffix can be
|
||||
* controlled with {@link #CONFIG_SEQUENCE_PER_ENTITY_SUFFIX} option.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static final String CONFIG_PREFER_SEQUENCE_PER_ENTITY = "prefer_sequence_per_entity";
|
||||
|
||||
/**
|
||||
* Indicates the suffix to use in naming the identifier sequence/table name, by appending the suffix to
|
||||
* the name of the entity. Used in conjunction with {@link #CONFIG_PREFER_SEQUENCE_PER_ENTITY}.
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static final String CONFIG_SEQUENCE_PER_ENTITY_SUFFIX = "sequence_per_entity_suffix";
|
||||
|
||||
/**
|
||||
@ -160,12 +125,6 @@ public class SequenceStyleGenerator
|
||||
*/
|
||||
public static final String DEF_SEQUENCE_SUFFIX = "_SEQ";
|
||||
|
||||
/**
|
||||
* Indicates the optimizer to use, either naming a {@link Optimizer} implementation class or naming
|
||||
* a {@link StandardOptimizerDescriptor} by name
|
||||
*/
|
||||
public static final String OPT_PARAM = "optimizer";
|
||||
|
||||
/**
|
||||
* A flag to force using a table as the underlying structure rather than a sequence.
|
||||
*/
|
||||
@ -317,41 +276,65 @@ protected QualifiedName determineSequenceName(
|
||||
Dialect dialect,
|
||||
JdbcEnvironment jdbcEnv,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX );
|
||||
final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( CATALOG, params )
|
||||
);
|
||||
final Identifier schema = jdbcEnv.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( SCHEMA, params )
|
||||
);
|
||||
|
||||
String fallbackSequenceName = DEF_SEQUENCE_NAME;
|
||||
final Boolean preferGeneratorNameAsDefaultName = serviceRegistry.getService( ConfigurationService.class )
|
||||
.getSetting( AvailableSettings.PREFER_GENERATOR_NAME_AS_DEFAULT_SEQUENCE_NAME, StandardConverters.BOOLEAN, true );
|
||||
if ( preferGeneratorNameAsDefaultName ) {
|
||||
final String generatorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
|
||||
if ( StringHelper.isNotEmpty( generatorName ) ) {
|
||||
fallbackSequenceName = generatorName;
|
||||
final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params );
|
||||
if ( StringHelper.isNotEmpty( sequenceName ) ) {
|
||||
// we have an explicit name, use it
|
||||
if ( sequenceName.contains( "." ) ) {
|
||||
//
|
||||
return QualifiedNameParser.INSTANCE.parse( sequenceName );
|
||||
}
|
||||
else {
|
||||
return new QualifiedNameParser.NameParts(
|
||||
catalog,
|
||||
schema,
|
||||
jdbcEnv.getIdentifierHelper().toIdentifier( sequenceName )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
|
||||
final String defaultSequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
|
||||
? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix
|
||||
: fallbackSequenceName;
|
||||
// otherwise, determine an implicit name to use
|
||||
final String implicitName = determineImplicitName( params, jdbcEnv, serviceRegistry );
|
||||
return new QualifiedNameParser.NameParts(
|
||||
catalog,
|
||||
schema,
|
||||
jdbcEnv.getIdentifierHelper().toIdentifier( implicitName )
|
||||
);
|
||||
}
|
||||
|
||||
final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, defaultSequenceName );
|
||||
if ( sequenceName.contains( "." ) ) {
|
||||
return QualifiedNameParser.INSTANCE.parse( sequenceName );
|
||||
private String determineImplicitName(Properties params, JdbcEnvironment jdbcEnv, ServiceRegistry serviceRegistry) {
|
||||
final String annotationGeneratorName = params.getProperty( IdentifierGenerator.GENERATOR_NAME );
|
||||
final String base = ConfigurationHelper.getString( IMPLICIT_NAME_BASE, params );
|
||||
final String suffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX );
|
||||
|
||||
if ( ! Objects.equals( suffix, DEF_SEQUENCE_SUFFIX ) ) {
|
||||
// an "implicit name suffix" was specified
|
||||
if ( StringHelper.isNotEmpty( base ) ) {
|
||||
if ( Identifier.isQuoted( base ) ) {
|
||||
return "`" + Identifier.unQuote( base ) + suffix + "`";
|
||||
}
|
||||
return base + suffix;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// todo : need to incorporate implicit catalog and schema names
|
||||
final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( CATALOG, params )
|
||||
);
|
||||
final Identifier schema = jdbcEnv.getIdentifierHelper().toIdentifier(
|
||||
ConfigurationHelper.getString( SCHEMA, params )
|
||||
);
|
||||
return new QualifiedNameParser.NameParts(
|
||||
catalog,
|
||||
schema,
|
||||
jdbcEnv.getIdentifierHelper().toIdentifier( sequenceName )
|
||||
);
|
||||
|
||||
if ( StringHelper.isNotEmpty( annotationGeneratorName ) ) {
|
||||
return annotationGeneratorName;
|
||||
}
|
||||
|
||||
if ( StringHelper.isNotEmpty( base ) ) {
|
||||
if ( Identifier.isQuoted( base ) ) {
|
||||
return "`" + Identifier.unQuote( base ) + suffix + "`";
|
||||
}
|
||||
return base + suffix;
|
||||
}
|
||||
|
||||
throw new MappingException( "Unable to determine sequence name" );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,34 +199,6 @@ public class TableGenerator implements PersistentIdentifierGenerator, Configurab
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static final int DEF_SEGMENT_LENGTH = 255;
|
||||
|
||||
/**
|
||||
* Indicates the initial value to use. The default value is {@link #DEFAULT_INITIAL_VALUE}
|
||||
*/
|
||||
public static final String INITIAL_PARAM = "initial_value";
|
||||
|
||||
/**
|
||||
* The default {@link #INITIAL_PARAM} value
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static final int DEFAULT_INITIAL_VALUE = 1;
|
||||
|
||||
/**
|
||||
* Indicates the increment size to use. The default value is {@link #DEFAULT_INCREMENT_SIZE}
|
||||
*/
|
||||
public static final String INCREMENT_PARAM = "increment_size";
|
||||
|
||||
/**
|
||||
* The default {@link #INCREMENT_PARAM} value
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public static final int DEFAULT_INCREMENT_SIZE = 1;
|
||||
|
||||
/**
|
||||
* Indicates the optimizer to use, either naming a {@link Optimizer} implementation class or by naming
|
||||
* a {@link StandardOptimizerDescriptor} by name
|
||||
*/
|
||||
public static final String OPT_PARAM = "optimizer";
|
||||
|
||||
private boolean storeLastUsedValue;
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.hibernate.boot.model.source.internal.hbm.CommaSeparatedStringHelper;
|
||||
|
@ -36,6 +36,7 @@
|
||||
import org.hibernate.engine.spi.Mapping;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
import org.hibernate.id.OptimizableGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
@ -284,33 +285,39 @@ public IdentifierGenerator createIdentifierGenerator(
|
||||
return identifierGenerator;
|
||||
}
|
||||
|
||||
Properties params = new Properties();
|
||||
final Properties params = new Properties();
|
||||
|
||||
//if the hibernate-mapping did not specify a schema/catalog, use the defaults
|
||||
//specified by properties - but note that if the schema/catalog were specified
|
||||
//in hibernate-mapping, or as params, they will already be initialized and
|
||||
//will override the values set here (they are in identifierGeneratorProperties)
|
||||
if ( defaultSchema!=null ) {
|
||||
params.setProperty(PersistentIdentifierGenerator.SCHEMA, defaultSchema);
|
||||
if ( defaultSchema != null ) {
|
||||
params.setProperty( PersistentIdentifierGenerator.SCHEMA, defaultSchema);
|
||||
}
|
||||
if ( defaultCatalog!=null ) {
|
||||
params.setProperty(PersistentIdentifierGenerator.CATALOG, defaultCatalog);
|
||||
|
||||
if ( defaultCatalog != null ) {
|
||||
params.setProperty( PersistentIdentifierGenerator.CATALOG, defaultCatalog );
|
||||
}
|
||||
|
||||
// default initial value and allocation size per-JPA defaults
|
||||
params.setProperty( OptimizableGenerator.INITIAL_PARAM, String.valueOf( OptimizableGenerator.DEFAULT_INITIAL_VALUE ) );
|
||||
params.setProperty( OptimizableGenerator.INCREMENT_PARAM, String.valueOf( OptimizableGenerator.DEFAULT_INCREMENT_SIZE ) );
|
||||
|
||||
//init the table here instead of earlier, so that we can get a quoted table name
|
||||
//TODO: would it be better to simply pass the qualified table name, instead of
|
||||
// splitting it up into schema/catalog/table names
|
||||
String tableName = getTable().getQuotedName(dialect);
|
||||
final String tableName = getTable().getQuotedName( dialect );
|
||||
params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
|
||||
|
||||
//pass the column name (a generated id almost always has a single column)
|
||||
String columnName = ( (Column) getColumnIterator().next() ).getQuotedName(dialect);
|
||||
final String columnName = ( (Column) getColumnIterator().next() ).getQuotedName( dialect );
|
||||
params.setProperty( PersistentIdentifierGenerator.PK, columnName );
|
||||
|
||||
//pass the entity-name, if not a collection-id
|
||||
if (rootClass!=null) {
|
||||
if ( rootClass != null ) {
|
||||
params.setProperty( IdentifierGenerator.ENTITY_NAME, rootClass.getEntityName() );
|
||||
params.setProperty( IdentifierGenerator.JPA_ENTITY_NAME, rootClass.getJpaEntityName() );
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, rootClass.getJpaEntityName() );
|
||||
|
||||
final StringBuilder tables = new StringBuilder();
|
||||
final Iterator<Table> itr = rootClass.getIdentityTables().iterator();
|
||||
@ -325,10 +332,11 @@ public IdentifierGenerator createIdentifierGenerator(
|
||||
}
|
||||
else {
|
||||
params.setProperty( PersistentIdentifierGenerator.TABLES, tableName );
|
||||
params.setProperty( OptimizableGenerator.IMPLICIT_NAME_BASE, tableName );
|
||||
}
|
||||
|
||||
if ( identifierGeneratorProperties != null ) {
|
||||
params.putAll(identifierGeneratorProperties);
|
||||
params.putAll( identifierGeneratorProperties );
|
||||
}
|
||||
|
||||
// TODO : we should pass along all settings once "config lifecycle" is hashed out...
|
||||
|
@ -84,7 +84,7 @@ public void testAutoEntity(SessionFactoryScope scope) {
|
||||
IdentifierGenerator generator = persister.getIdentifierGenerator();
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, seqGenerator.getDatabaseStructure().getName() );
|
||||
assertEquals( "AutoEntity_SEQ", seqGenerator.getDatabaseStructure().getName() );
|
||||
assertEquals( SequenceStyleGenerator.DEFAULT_INITIAL_VALUE, seqGenerator.getDatabaseStructure().getInitialValue() );
|
||||
assertEquals( SequenceStyleGenerator.DEFAULT_INCREMENT_SIZE, seqGenerator.getDatabaseStructure().getIncrementSize() );
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public void testHibernateSequenceSchema(SessionFactoryScope scope) {
|
||||
assertTrue( SequenceStyleGenerator.class.isInstance( generator ) );
|
||||
SequenceStyleGenerator seqGenerator = (SequenceStyleGenerator) generator;
|
||||
assertEquals(
|
||||
Table.qualify( null, SCHEMA_NAME, SequenceStyleGenerator.DEF_SEQUENCE_NAME ),
|
||||
Table.qualify( null, SCHEMA_NAME, "HibernateSequenceEntity_SEQ" ),
|
||||
seqGenerator.getDatabaseStructure().getName()
|
||||
);
|
||||
}
|
||||
|
@ -54,17 +54,23 @@ public void before() throws Exception {
|
||||
|
||||
final URL hbmXmlUrl = getClass().getClassLoader().getResource( HBM_RESOURCE_NAME );
|
||||
if ( hbmXmlUrl == null ) {
|
||||
throw couldNotFindHbmXmlFile();
|
||||
throw couldNotFindHbmXmlResource();
|
||||
}
|
||||
hbmXmlFile = new File( hbmXmlUrl.getFile() );
|
||||
if ( ! hbmXmlFile.exists() ) {
|
||||
throw couldNotFindHbmXmlFile();
|
||||
throw couldNotFindHbmXmlFile( hbmXmlFile );
|
||||
}
|
||||
hbmXmlBinFile = CacheableFileXmlSource.determineCachedFile( hbmXmlFile );
|
||||
}
|
||||
|
||||
private Exception couldNotFindHbmXmlFile() {
|
||||
throw new IllegalStateException( "Could not locate hbm.xml file by resource lookup" );
|
||||
private Exception couldNotFindHbmXmlResource() {
|
||||
throw new IllegalStateException( "Could not locate `" + HBM_RESOURCE_NAME + "` by resource lookup" );
|
||||
}
|
||||
|
||||
private Exception couldNotFindHbmXmlFile(File file) {
|
||||
throw new IllegalStateException(
|
||||
"File `" + file.getAbsolutePath() + "` resolved from `" + HBM_RESOURCE_NAME + "` resource-lookup does not exist"
|
||||
);
|
||||
}
|
||||
|
||||
@After
|
||||
|
@ -171,7 +171,7 @@ private List getCollectionElementRows(int id, SessionFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity( name = "AnEntity" )
|
||||
@Table(name = "AnEntity")
|
||||
public static class AnEntity {
|
||||
@Id
|
||||
@ -184,7 +184,7 @@ public static class AnEntity {
|
||||
private List<String> aCollection = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity( name = "NullableElementsEntity" )
|
||||
@Table(name = "NullableElementsEntity")
|
||||
public static class NullableElementsEntity {
|
||||
@Id
|
||||
|
@ -164,7 +164,7 @@ private List getCollectionElementRows(int id, SessionFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "AnEntity")
|
||||
@Table(name = "AnEntity")
|
||||
@GenericGenerator(name = "increment", strategy = "increment")
|
||||
public static class AnEntity {
|
||||
|
@ -165,7 +165,7 @@ private List getCollectionElementRows(int id, SessionFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "AnEntity")
|
||||
@Table(name = "AnEntity")
|
||||
public static class AnEntity {
|
||||
@Id
|
||||
|
@ -162,7 +162,7 @@ private List<?> getCollectionElementRows(int id, SessionFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "AnEntity")
|
||||
@Table(name = "AnEntity")
|
||||
public static class AnEntity {
|
||||
@Id
|
||||
|
@ -391,7 +391,7 @@ public void testMapKeyColumnNonInsertableNonUpdatableUnidirOneToMany(SessionFact
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "MyUser")
|
||||
@Table(name = "MyUser")
|
||||
static class User implements Serializable {
|
||||
@Id
|
||||
@ -416,7 +416,7 @@ public Integer getId() {
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "UserData")
|
||||
@Table(name = "UserData")
|
||||
static class UserData {
|
||||
@Id
|
||||
@ -428,7 +428,7 @@ static class UserData {
|
||||
private User user;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Address")
|
||||
@Table(name = "Address")
|
||||
static class Address {
|
||||
@Id
|
||||
@ -446,7 +446,7 @@ static class Address {
|
||||
private String addressText;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Detail")
|
||||
@Table(name = "Detail")
|
||||
static class Detail {
|
||||
@Id
|
||||
|
@ -128,7 +128,7 @@ private List<?> getCollectionElementRows(int id) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name="AnEntity")
|
||||
@Table(name="AnEntity")
|
||||
public static class AnEntity {
|
||||
@Id
|
||||
|
@ -91,7 +91,7 @@ void fetchSubGraphFromSubgraph(SessionFactoryScope scope) {
|
||||
//productSubgraph.addAttributeNodes( "productName" );
|
||||
|
||||
TypedQuery<CustomerOrder> query = em.createQuery(
|
||||
"SELECT o FROM EntityGraphUsingFetchGraphTest$CustomerOrder o", CustomerOrder.class
|
||||
"SELECT o FROM CustomerOrder o", CustomerOrder.class
|
||||
);
|
||||
query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
|
||||
final List<CustomerOrder> results = query.getResultList();
|
||||
@ -140,7 +140,7 @@ void fetchAttributeNodeByStringFromSubgraph(SessionFactoryScope scope) {
|
||||
productSubgraph.addAttributeNodes( "productName" );
|
||||
|
||||
TypedQuery<CustomerOrder> query = em.createQuery(
|
||||
"SELECT o FROM EntityGraphUsingFetchGraphTest$CustomerOrder o", CustomerOrder.class
|
||||
"SELECT o FROM CustomerOrder o", CustomerOrder.class
|
||||
);
|
||||
query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
|
||||
final List<CustomerOrder> results = query.getResultList();
|
||||
@ -201,7 +201,7 @@ void fetchAttributeNodeByAttributeFromSubgraph(SessionFactoryScope scope) {
|
||||
productSubgraph.addAttributeNodes( (Attribute) productEntityType.getAttribute( "productName" ) );
|
||||
|
||||
TypedQuery<CustomerOrder> query = em.createQuery(
|
||||
"SELECT o FROM EntityGraphUsingFetchGraphTest$CustomerOrder o", CustomerOrder.class
|
||||
"SELECT o FROM CustomerOrder o", CustomerOrder.class
|
||||
);
|
||||
query.setHint( GraphSemantic.LOAD.getJpaHintName(), entityGraph );
|
||||
final List<CustomerOrder> results = query.getResultList();
|
||||
@ -243,7 +243,7 @@ void fetchUsingHql(SessionFactoryScope scope) {
|
||||
session -> {
|
||||
final EntityManager em = session.unwrap( EntityManager.class );
|
||||
TypedQuery<CustomerOrder> query = em.createQuery(
|
||||
"SELECT o FROM EntityGraphUsingFetchGraphTest$CustomerOrder o left join fetch o.orderPosition pos left join fetch pos.product left join fetch o.shippingAddress", CustomerOrder.class
|
||||
"SELECT o FROM CustomerOrder o left join fetch o.orderPosition pos left join fetch pos.product left join fetch o.shippingAddress", CustomerOrder.class
|
||||
);
|
||||
final List<CustomerOrder> results = query.getResultList();
|
||||
|
||||
@ -283,7 +283,7 @@ private void assertEntityGraph(EntityGraph<CustomerOrder> entityGraph) {
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "CustomerOrder")
|
||||
@Table(name = "customerOrder")
|
||||
public static class CustomerOrder {
|
||||
@Id
|
||||
@ -300,7 +300,7 @@ public static class CustomerOrder {
|
||||
public Address shippingAddress;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Address")
|
||||
@Table(name = "address")
|
||||
public static class Address {
|
||||
@Id
|
||||
@ -310,7 +310,7 @@ public static class Address {
|
||||
public String city;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "OrderPosition")
|
||||
@Table(name = "orderPosition")
|
||||
public static class OrderPosition {
|
||||
@Id
|
||||
@ -324,7 +324,7 @@ public static class OrderPosition {
|
||||
public Product product;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Product")
|
||||
@Table(name = "product")
|
||||
public static class Product {
|
||||
@Id
|
||||
|
@ -16,9 +16,12 @@
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.id.OptimizableGenerator;
|
||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||
import org.hibernate.id.enhanced.DatabaseStructure;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.NoopOptimizer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.id.enhanced.PooledLoOptimizer;
|
||||
import org.hibernate.id.enhanced.PooledLoThreadLocalOptimizer;
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
@ -32,7 +35,11 @@
|
||||
import org.hibernate.testing.junit5.BaseUnitTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.testing.junit5.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@ -43,12 +50,12 @@
|
||||
public class SequenceStyleConfigUnitTest extends BaseUnitTest {
|
||||
|
||||
/**
|
||||
* Test all params defaulted with a dialect supporting sequences
|
||||
* Test all params defaulted with a dialect supporting pooled sequences
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultedSequenceBackedConfiguration() {
|
||||
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, SequenceDialect.class.getName() )
|
||||
.applySetting( AvailableSettings.DIALECT, PooledSequenceDialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
@ -60,9 +67,14 @@ public void testDefaultedSequenceBackedConfiguration() {
|
||||
new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) )
|
||||
);
|
||||
|
||||
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
|
||||
assertTrue( databaseStructure.isPhysicalSequence() );
|
||||
|
||||
final Optimizer optimizer = generator.getOptimizer();
|
||||
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
|
||||
assertEquals( optimizer.getIncrementSize(), OptimizableGenerator.DEFAULT_INCREMENT_SIZE );
|
||||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
@ -75,6 +87,10 @@ private Properties buildGeneratorPropertiesBase(StandardServiceRegistry serviceR
|
||||
PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER,
|
||||
new MetadataBuildingContextTestingImpl( serviceRegistry ).getObjectNameNormalizer()
|
||||
);
|
||||
props.put(
|
||||
PersistentIdentifierGenerator.IMPLICIT_NAME_BASE,
|
||||
"ID"
|
||||
);
|
||||
return props;
|
||||
}
|
||||
|
||||
@ -96,9 +112,14 @@ public void testDefaultedTableBackedConfiguration() {
|
||||
new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) )
|
||||
);
|
||||
|
||||
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
|
||||
final Optimizer optimizer = generator.getOptimizer();
|
||||
|
||||
assertFalse( databaseStructure.isPhysicalSequence() );
|
||||
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
|
||||
assertEquals( 50, databaseStructure.getIncrementSize());
|
||||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
@ -130,7 +151,7 @@ public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
|
||||
|
||||
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
@ -153,7 +174,7 @@ public void testDefaultOptimizerBasedOnIncrementBackedBySequence() {
|
||||
|
||||
assertClassAssignability( SequenceStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
@ -183,7 +204,7 @@ public void testDefaultOptimizerBasedOnIncrementBackedByTable() {
|
||||
|
||||
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
assertEquals( "ID_SEQ", generator.getDatabaseStructure().getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
@ -209,9 +230,14 @@ public void testForceTableUse() {
|
||||
new Database( new MetadataBuilderImpl.MetadataBuildingOptionsImpl( serviceRegistry ) )
|
||||
);
|
||||
|
||||
assertClassAssignability( TableStructure.class, generator.getDatabaseStructure().getClass() );
|
||||
assertClassAssignability( NoopOptimizer.class, generator.getOptimizer().getClass() );
|
||||
assertEquals( SequenceStyleGenerator.DEF_SEQUENCE_NAME, generator.getDatabaseStructure().getName() );
|
||||
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
|
||||
final Optimizer optimizer = generator.getOptimizer();
|
||||
|
||||
assertFalse( databaseStructure.isPhysicalSequence() );
|
||||
assertThat( optimizer, instanceOf( PooledOptimizer.class ) );
|
||||
assertEquals( 50, databaseStructure.getIncrementSize());
|
||||
|
||||
assertEquals( "ID_SEQ", databaseStructure.getName() );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( serviceRegistry );
|
||||
|
@ -120,7 +120,7 @@ public void test() {
|
||||
assertEquals( ITERATIONS, id.get() );
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity( name = "ApplicationConfigurationHBM2DDL" )
|
||||
@Table(name = "application_configurations")
|
||||
public static class ApplicationConfigurationHBM2DDL {
|
||||
|
||||
@ -142,7 +142,7 @@ public void setId(final Long id) {
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "ApplicationConfiguration")
|
||||
@Table(name = "application_configurations")
|
||||
public static class ApplicationConfiguration {
|
||||
|
||||
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
|
||||
package org.hibernate.orm.test.idgen;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests for scoping of generator names
|
||||
*
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@DomainModel( annotatedClasses = { IdGeneratorNameScopingTest.FirstEntity.class, IdGeneratorNameScopingTest.SecondEntity.class } )
|
||||
@SessionFactory
|
||||
public class IdGeneratorNameScopingTest {
|
||||
//
|
||||
@Test
|
||||
public void testLocalScoping() {
|
||||
// test Hibernate's default behavior which "violates" the spec but is much
|
||||
// more sane.
|
||||
// this works properly because Hibernate simply prefers the locally defined one
|
||||
buildMetadata( false );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGlobalScoping() {
|
||||
// now test JPA's strategy of globally scoping identifiers.
|
||||
// this will fail because both
|
||||
try {
|
||||
buildMetadata( true );
|
||||
fail();
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat( e, instanceOf( IllegalArgumentException.class ) );
|
||||
assertThat( e.getMessage(), startsWith( "Duplicate generator name" ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void buildMetadata(boolean jpaCompliantScoping) {
|
||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, jpaCompliantScoping )
|
||||
.build();
|
||||
|
||||
try {
|
||||
// this will fail with global scoping and pass with local scoping
|
||||
new MetadataSources( registry )
|
||||
.addAnnotatedClass( FirstEntity.class )
|
||||
.addAnnotatedClass( SecondEntity.class )
|
||||
.buildMetadata();
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( registry );
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "FirstEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier_2",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5,
|
||||
initialValue = 1
|
||||
)
|
||||
public static class FirstEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "SecondEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5,
|
||||
initialValue = 10
|
||||
)
|
||||
public static class SecondEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.biginteger.increment;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/increment/Mapping.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class BigIntegerIncrementGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void testBasics(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Entity entity = new Entity( "BigInteger + increment #1" );
|
||||
session.save( entity );
|
||||
Entity entity2 = new Entity( "BigInteger + increment #2" );
|
||||
session.save( entity2 );
|
||||
|
||||
session.flush();
|
||||
|
||||
assertEquals( BigInteger.valueOf( 1 ), entity.getId() );
|
||||
assertEquals( BigInteger.valueOf( 2 ), entity2.getId() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.createQuery( "delete Entity" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.biginteger.increment;
|
||||
package org.hibernate.orm.test.idgen.biginteger.increment;
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
@ -13,7 +13,7 @@
|
||||
Demonstrates use of simple increment generator on a BigInteger property.
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.biginteger.increment">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.biginteger.increment">
|
||||
|
||||
<class name="Entity">
|
||||
<id name="id" column="ID" type="big_integer">
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.biginteger.sequence;
|
||||
|
||||
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/Mapping.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
|
||||
public class BigIntegerSequenceGeneratorTest {
|
||||
|
||||
@Test
|
||||
public void testBasics(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
Entity entity = new Entity( "BigInteger + sequence #1" );
|
||||
session.save( entity );
|
||||
Entity entity2 = new Entity( "BigInteger + sequence #2" );
|
||||
session.save( entity2 );
|
||||
|
||||
// previously these checks were commented out due to the comment...
|
||||
|
||||
// hsqldb defines different behavior for the initial select from a sequence
|
||||
// then say oracle
|
||||
// assertEquals( BigInteger.valueOf( 1 ), entity.getId() );
|
||||
// assertEquals( BigInteger.valueOf( 2 ), entity2.getId() );
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
session.createQuery( "delete from Entity" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
|
||||
package org.hibernate.orm.test.idgen.biginteger.sequence;
|
||||
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* This test explicitly maps scale="0" for the sequence column. It works around the arithmetic
|
||||
* overflow that happens because the generated column cannot accommodate the SQL Server
|
||||
* sequence that starts, by default, with the value, -9,223,372,036,854,775,808.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/biginteger/sequence/ZeroScaleMapping.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
|
||||
public class BigIntegerSequenceGeneratorZeroScaleTest extends BigIntegerSequenceGeneratorTest {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9250")
|
||||
public void testBasics(SessionFactoryScope scope) {
|
||||
super.testBasics( scope );
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +1,13 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.biginteger.sequence;
|
||||
package org.hibernate.orm.test.idgen.biginteger.sequence;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* TODO : javadoc
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Entity {
|
||||
private BigInteger id;
|
||||
private String name;
|
@ -13,7 +13,7 @@
|
||||
Demonstrates use of a sequence generator on a BigInteger property.
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.biginteger.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.biginteger.sequence">
|
||||
|
||||
<class name="Entity">
|
||||
<id name="id" column="ID" type="big_integer">
|
@ -13,7 +13,7 @@
|
||||
Demonstrates use of a sequence generator on a BigInteger property.
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.biginteger.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.biginteger.sequence">
|
||||
|
||||
<class name="Entity">
|
||||
<id name="id" type="big_integer">
|
@ -2,9 +2,9 @@
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table.concurrent;
|
||||
package org.hibernate.orm.test.idgen.enhanced;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -12,17 +12,14 @@
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
@ -32,11 +29,8 @@
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.entitynonentity.Voice;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.auto;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.CollectionId;
|
||||
import org.hibernate.annotations.Type;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.id.IdentifierGenerator;
|
||||
import org.hibernate.id.IncrementGenerator;
|
||||
import org.hibernate.id.UUIDGenerator;
|
||||
import org.hibernate.id.enhanced.DatabaseStructure;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory;
|
||||
import org.hibernate.mapping.IdentifierBag;
|
||||
import org.hibernate.mapping.KeyValue;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.tool.schema.Action;
|
||||
|
||||
import org.hibernate.testing.orm.junit.FailureExpectedExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.equalToIgnoringCase;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@ExtendWith( FailureExpectedExtension.class )
|
||||
public class AutoGenerationTypeTests {
|
||||
@Test
|
||||
public void testAutoDefaults() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator entityIdGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final DatabaseStructure database1Structure = entityIdGenerator.getDatabaseStructure();
|
||||
|
||||
// implicit name : `${entity-name}_seq`
|
||||
assertThat( database1Structure.getName(), equalToIgnoringCase( "Entity1_seq" ) );
|
||||
assertThat( database1Structure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAutoGeneratedValueGenerator() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity2.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final SequenceStyleGenerator idGenerator = (SequenceStyleGenerator) idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final DatabaseStructure database2Structure = idGenerator.getDatabaseStructure();
|
||||
|
||||
// GeneratedValue#generator value
|
||||
assertThat( database2Structure.getName(), equalToIgnoringCase( "id_seq" ) );
|
||||
assertThat( database2Structure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionId() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.addAnnotatedClass( Entity2.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entity1Binding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Entity1#theTwos collection-id - implicit `${collection_table}_seq`
|
||||
|
||||
final Property theTwos = entity1Binding.getProperty( "theTwos" );
|
||||
final IdentifierBag idBagMapping = (IdentifierBag) theTwos.getValue();
|
||||
final KeyValue collectionIdMapping = idBagMapping.getIdentifier();
|
||||
final SequenceStyleGenerator collectionIdGenerator = (SequenceStyleGenerator) collectionIdMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
null
|
||||
);
|
||||
|
||||
final DatabaseStructure idBagIdGeneratorDbStructure = collectionIdGenerator.getDatabaseStructure();
|
||||
|
||||
assertThat( idBagIdGeneratorDbStructure.getName(), equalToIgnoringCase( "tbl_2_seq" ) );
|
||||
assertThat( idBagIdGeneratorDbStructure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUuid() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity4.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity4.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
assertThat( idGenerator, instanceOf( UUIDGenerator.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncrement() {
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity3.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity3.class.getName() );
|
||||
final KeyValue idMapping = entityBinding.getRootClass().getIdentifier();
|
||||
final IdentifierGenerator idGenerator = idMapping.createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
assertThat( idGenerator, instanceOf( IncrementGenerator.class ) );
|
||||
}
|
||||
|
||||
@Entity( name = "Entity1" )
|
||||
@Table( name = "tbl_1" )
|
||||
public static class Entity1 {
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
private Integer id;
|
||||
|
||||
@OneToMany( mappedBy = "theOne" )
|
||||
@CollectionId(
|
||||
columns = @Column( name = "child_" ),
|
||||
type = @Type( type = "int" ),
|
||||
generator = "sequence"
|
||||
)
|
||||
private Collection<Entity2> theTwos;
|
||||
}
|
||||
|
||||
@Entity( name = "Entity2" )
|
||||
@Table( name = "tbl_2" )
|
||||
public static class Entity2 {
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO, generator = "id_seq" )
|
||||
private Integer id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn
|
||||
private Entity1 theOne;
|
||||
}
|
||||
|
||||
@Entity( name = "Entity3" )
|
||||
@Table( name = "tbl_3" )
|
||||
public static class Entity3 {
|
||||
@Id
|
||||
@GeneratedValue( generator = "increment" )
|
||||
private Integer id;
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Entity( name = "Entity4" )
|
||||
@Table( name = "tbl_4" )
|
||||
public static class Entity4 {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private UUID id;
|
||||
private String name;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
everytime when generating a value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.forcedtable">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.forcedtable">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_TBL_BSC_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.forcedtable;
|
||||
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.NoopOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/enhanced/forcedtable/Basic.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class BasicForcedTableSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getDatabaseStructure(), instanceOf( TableStructure.class ) );
|
||||
assertThat( generator.getOptimizer(), instanceOf( NoopOptimizer.class ) );
|
||||
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
int count = 5;
|
||||
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
session.save( entity );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entity.getId().longValue() );
|
||||
assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.forcedtable;
|
||||
package org.hibernate.orm.test.idgen.enhanced.forcedtable;
|
||||
|
||||
|
||||
/**
|
@ -15,7 +15,7 @@
|
||||
avoid hitting the database to generate each value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.forcedtable">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.forcedtable">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_TBL_HILO_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.forcedtable;
|
||||
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/enhanced/forcedtable/HiLo.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class HiLoForcedTableSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getDatabaseStructure(), instanceOf( TableStructure.class ) );
|
||||
assertThat( generator.getOptimizer(), instanceOf( HiLoOptimizer.class ) );
|
||||
|
||||
final HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
|
||||
long expectedId = i + 1;
|
||||
assertThat( entity.getId().longValue(), is( expectedId ) );
|
||||
assertThat( ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue(), is( 1L ) );
|
||||
assertThat( ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue(), is( i + 1L ) );
|
||||
assertThat( ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue(), is( increment + 1L ) );
|
||||
}
|
||||
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
s.save( entity );
|
||||
|
||||
long expectedId = optimizer.getIncrementSize() + 1;
|
||||
assertThat( entity.getId().longValue(), is( expectedId ) );
|
||||
// initialization + clock-over
|
||||
assertThat( ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue(), is( 2L ) );
|
||||
assertThat( ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue(), is( increment + 1L ) );
|
||||
assertThat( ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue(), is( ( increment * 2L ) + 1L ) );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
avoid hitting the database to generate each value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.forcedtable">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.forcedtable">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_TBL_POOL_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.forcedtable;
|
||||
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@DomainModel(
|
||||
xmlMappings = "org/hibernate/orm/test/idgen/enhanced/forcedtable/Pooled.hbm.xml"
|
||||
)
|
||||
@SessionFactory
|
||||
public class PooledForcedTableSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getDatabaseStructure(), instanceOf( TableStructure.class ) );
|
||||
assertThat( generator.getOptimizer(), instanceOf( PooledOptimizer.class ) );
|
||||
|
||||
final PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
final int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entity.getId().longValue() );
|
||||
// NOTE : initialization calls table twice
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
s.save( entity );
|
||||
long expectedId = optimizer.getIncrementSize() + 2;
|
||||
assertEquals( expectedId, entity.getId().longValue() );
|
||||
// initialization (2) + clock over
|
||||
assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
everytime when generating a value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.sequence">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_BSC_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.sequence;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
@DomainModel(
|
||||
xmlMappings = {
|
||||
"org/hibernate/orm/test/idgen/enhanced/sequence/Basic.hbm.xml",
|
||||
"org/hibernate/orm/test/idgen/enhanced/sequence/Dedicated.hbm.xml"
|
||||
}
|
||||
)
|
||||
@SessionFactory
|
||||
public class BasicSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
|
||||
final int count = 5;
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
|
||||
long expectedId = i + 1;
|
||||
|
||||
assertEquals( expectedId, entity.getId().longValue() );
|
||||
assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer()
|
||||
.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-6790")
|
||||
public void testSequencePerEntity(SessionFactoryScope scope) {
|
||||
final String overriddenEntityName = "SpecialEntity";
|
||||
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( overriddenEntityName );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertEquals( overriddenEntityName + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX, generator.getDatabaseStructure().getName() );
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
Entity entity1 = new Entity( "1" );
|
||||
s.save( overriddenEntityName, entity1 );
|
||||
Entity entity2 = new Entity( "2" );
|
||||
s.save( overriddenEntityName, entity2 );
|
||||
|
||||
assertEquals( 1, entity1.getId().intValue() );
|
||||
assertEquals( 2, entity2.getId().intValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void dropTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
generator, with dedicated sequence for each entity.
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.sequence">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_BSC_ENTITY" entity-name="SpecialEntity">
|
||||
<id name="id" column="ID" type="long">
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.sequence;
|
||||
package org.hibernate.orm.test.idgen.enhanced.sequence;
|
||||
|
||||
|
||||
/**
|
@ -15,7 +15,7 @@
|
||||
avoid hitting the database to generate each value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.sequence">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_HILO_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.sequence;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.DerbyDialect;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.Optimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.ServiceRegistry;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Nathan Xu
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-13783")
|
||||
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsSequences.class )
|
||||
@ServiceRegistry(
|
||||
settings = @Setting( name = AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, value = "EXCEPTION" )
|
||||
)
|
||||
@DomainModel( annotatedClasses = HiLoSequenceMismatchStrategyTest.TestEntity.class )
|
||||
@SessionFactory
|
||||
public class HiLoSequenceMismatchStrategyTest {
|
||||
|
||||
public final static String sequenceName = "ID_SEQ_HILO_SEQ";
|
||||
|
||||
@BeforeEach
|
||||
public void dropDatabaseSequence(SessionFactoryScope scope) {
|
||||
final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
|
||||
|
||||
final String[] dropSequenceStatements = dialect.getSequenceSupport().getDropSequenceStrings( sequenceName );
|
||||
final String[] createSequenceStatements = dialect.getSequenceSupport().getCreateSequenceStrings( sequenceName, 1, 1 );
|
||||
|
||||
final ConnectionProvider connectionProvider = scope.getSessionFactory()
|
||||
.getServiceRegistry()
|
||||
.getService( ConnectionProvider.class );
|
||||
|
||||
try ( Connection connection = connectionProvider.getConnection();
|
||||
Statement statement = connection.createStatement() ) {
|
||||
|
||||
for ( String dropSequenceStatement : dropSequenceStatements ) {
|
||||
try {
|
||||
statement.execute( dropSequenceStatement );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
System.out.printf( "TEST DEBUG : dropping sequence failed [`%s`] - %s", dropSequenceStatement, e.getMessage() );
|
||||
System.out.println();
|
||||
e.printStackTrace( System.out );
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
for ( String createSequenceStatement : createSequenceStatements ) {
|
||||
statement.execute( createSequenceStatement );
|
||||
}
|
||||
connection.commit();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceMismatchStrategyNotApplied(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( TestEntity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
|
||||
|
||||
final Optimizer optimizer = generator.getOptimizer();
|
||||
assertThat( optimizer, instanceOf( HiLoOptimizer.class ) );
|
||||
assertThat( optimizer.getIncrementSize(), not( is( 1 ) ) );
|
||||
|
||||
assertThat( generator.getDatabaseStructure().getName(), is( sequenceName ) );
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
public static class TestEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator")
|
||||
@GenericGenerator(name = "hilo_sequence_generator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {
|
||||
@Parameter(name = "sequence_name", value = sequenceName),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "10"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
})
|
||||
private Long id;
|
||||
|
||||
private String aString;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.sequence;
|
||||
|
||||
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/idgen/enhanced/sequence/HiLo.hbm.xml" )
|
||||
@SessionFactory
|
||||
public class HiLoSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getOptimizer(), instanceOf( HiLoOptimizer.class ) );
|
||||
|
||||
final HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
|
||||
final int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
|
||||
// initialization
|
||||
assertEquals( 1, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
// initialization
|
||||
assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
s.save( entity );
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization
|
||||
assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
avoid hitting the database to generate each value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.sequence">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.sequence">
|
||||
|
||||
<class name="Entity" table="ID_SEQ_POOL_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.sequence;
|
||||
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/idgen/enhanced/sequence/Pooled.hbm.xml" )
|
||||
@SessionFactory
|
||||
public class PooledSequenceTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( SequenceStyleGenerator.class ) );
|
||||
|
||||
final SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getOptimizer(), instanceOf( PooledOptimizer.class ) );
|
||||
|
||||
final PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
final int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(session) -> {
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
session.save( entity );
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization calls seq twice
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization calls seq twice
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
session.save( entity );
|
||||
assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() ); // initialization (2) + clock over
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization (2) + clock over
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.table">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.table">
|
||||
|
||||
<identifier-generator name="table" class="org.hibernate.id.enhanced.TableGenerator"/>
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.table;
|
||||
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/idgen/enhanced/table/Basic.hbm.xml" )
|
||||
@SessionFactory
|
||||
public class BasicTableTest {
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( TableGenerator.class ) );
|
||||
|
||||
final TableGenerator generator = ( TableGenerator ) persister.getIdentifierGenerator();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
int count = 5;
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entity.getId().longValue() );
|
||||
assertEquals( expectedId, generator.getTableAccessCount() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table;
|
||||
package org.hibernate.orm.test.idgen.enhanced.table;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@ -20,33 +20,29 @@
|
||||
import org.hibernate.type.IntegerType;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class Db2GenerationTest extends BaseUnitTestCase {
|
||||
public class Db2GenerationTest {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9850" )
|
||||
public void testNewGeneratorTableCreationOnDb2() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, DB2Dialect.class.getName() )
|
||||
.build();
|
||||
|
||||
try {
|
||||
Metadata metadata = new MetadataSources( ssr )
|
||||
.buildMetadata();
|
||||
final Metadata metadata = new MetadataSources( ssr ).buildMetadata();
|
||||
|
||||
assertEquals( 0, metadata.getDatabase().getDefaultNamespace().getTables().size() );
|
||||
|
||||
TableGenerator generator = new TableGenerator();
|
||||
final TableGenerator generator = new TableGenerator();
|
||||
|
||||
Properties properties = new Properties();
|
||||
generator.configure( IntegerType.INSTANCE, properties, ssr );
|
||||
generator.configure( IntegerType.INSTANCE, new Properties(), ssr );
|
||||
|
||||
generator.registerExportables( metadata.getDatabase() );
|
||||
|
||||
@ -54,22 +50,17 @@ public void testNewGeneratorTableCreationOnDb2() {
|
||||
|
||||
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
|
||||
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata );
|
||||
assertContains( "sequence_name varchar(255) not null", createCommands[0] );
|
||||
assertThat( createCommands[0], containsString( "sequence_name varchar(255) not null" ) );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
||||
}
|
||||
}
|
||||
|
||||
private void assertContains(String subStr, String str) {
|
||||
if ( !str.contains( subStr ) ) {
|
||||
Assert.fail( "String [" + str + "] did not contain expected substring [" + subStr + "]" );
|
||||
}
|
||||
}
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9850" )
|
||||
public void testLegacyGeneratorTableCreationOnDb2() {
|
||||
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
|
||||
.applySetting( AvailableSettings.DIALECT, DB2Dialect.class.getName() )
|
||||
.build();
|
||||
|
||||
@ -90,7 +81,7 @@ public void testLegacyGeneratorTableCreationOnDb2() {
|
||||
|
||||
final Table table = metadata.getDatabase().getDefaultNamespace().getTables().iterator().next();
|
||||
final String[] createCommands = new DB2Dialect().getTableExporter().getSqlCreateStrings( table, metadata );
|
||||
assertContains( "sequence_name varchar(255) not null", createCommands[0] );
|
||||
assertThat( createCommands[0], containsString( "sequence_name varchar(255) not null" ) );
|
||||
}
|
||||
finally {
|
||||
StandardServiceRegistryBuilder.destroy( ssr );
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table;
|
||||
package org.hibernate.orm.test.idgen.enhanced.table;
|
||||
|
||||
|
||||
/**
|
@ -9,7 +9,7 @@
|
||||
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.table">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.table">
|
||||
|
||||
<identifier-generator name="table" class="org.hibernate.id.enhanced.TableGenerator"/>
|
||||
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.table;
|
||||
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/idgen/enhanced/table/HiLo.hbm.xml" )
|
||||
@SessionFactory
|
||||
public class HiLoTableTest {
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( TableGenerator.class ) );
|
||||
|
||||
final TableGenerator generator = (TableGenerator) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getOptimizer(), instanceOf( HiLoOptimizer.class ) );
|
||||
|
||||
final HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
final int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
assertEquals( 1, generator.getTableAccessCount() ); // initialization
|
||||
assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
s.save( entity );
|
||||
assertEquals( 2, generator.getTableAccessCount() ); // initialization
|
||||
assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(session) -> session.createQuery( "delete Entity" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@
|
||||
avoid hitting the database to generate each value).
|
||||
-->
|
||||
|
||||
<hibernate-mapping package="org.hibernate.test.idgen.enhanced.table">
|
||||
<hibernate-mapping package="org.hibernate.orm.test.idgen.enhanced.table">
|
||||
|
||||
<class name="Entity" table="ID_TBL_POOL_ENTITY">
|
||||
<id name="id" column="ID" type="long">
|
@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.enhanced.table;
|
||||
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@DomainModel( xmlMappings = "org/hibernate/orm/test/idgen/enhanced/table/Pooled.hbm.xml" )
|
||||
@SessionFactory
|
||||
public class PooledTableTest {
|
||||
@Test
|
||||
public void testNormalBoundary(SessionFactoryScope scope) {
|
||||
final EntityPersister persister = scope.getSessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertThat( persister.getIdentifierGenerator(), instanceOf( TableGenerator.class ) );
|
||||
|
||||
final TableGenerator generator = (TableGenerator) persister.getIdentifierGenerator();
|
||||
assertThat( generator.getOptimizer(), instanceOf( PooledOptimizer.class ) );
|
||||
|
||||
final PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
final int increment = optimizer.getIncrementSize();
|
||||
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
final Entity entity = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entity );
|
||||
// initialization calls seq twice
|
||||
assertEquals( 2, generator.getTableAccessCount() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
|
||||
// now force a "clock over"
|
||||
final Entity entity = new Entity( "" + increment );
|
||||
s.save( entity );
|
||||
|
||||
// initialization (2) + clock over
|
||||
assertEquals( 3, generator.getTableAccessCount() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (s) -> s.createQuery( "delete Entity" ).executeUpdate() );
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.foreign;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.Setting;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12738")
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
ForeignGeneratorResourceLocalTest.Contract.class,
|
||||
ForeignGeneratorResourceLocalTest.Customer.class,
|
||||
ForeignGeneratorResourceLocalTest.CustomerContractRelation.class
|
||||
},
|
||||
integrationSettings = {
|
||||
@Setting(
|
||||
name = AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY,
|
||||
value = "jta"
|
||||
),
|
||||
@Setting(
|
||||
name = AvailableSettings.JTA_PLATFORM,
|
||||
value = "org.hibernate.testing.jta.TestingJtaPlatformImpl"
|
||||
),
|
||||
}
|
||||
)
|
||||
public class ForeignGeneratorJtaTest extends ForeignGeneratorResourceLocalTest {
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.foreign;
|
||||
package org.hibernate.orm.test.idgen.foreign;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@ -28,146 +28,122 @@
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.junit.Test;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12738")
|
||||
public class ForeignGeneratorResourceLocalTest extends BaseEntityManagerFunctionalTestCase {
|
||||
@Jpa(
|
||||
annotatedClasses = {
|
||||
ForeignGeneratorResourceLocalTest.Contract.class,
|
||||
ForeignGeneratorResourceLocalTest.Customer.class,
|
||||
ForeignGeneratorResourceLocalTest.CustomerContractRelation.class
|
||||
}
|
||||
)
|
||||
public class ForeignGeneratorResourceLocalTest {
|
||||
private static final Logger log = Logger.getLogger( ForeignGeneratorResourceLocalTest.class );
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Contract.class,
|
||||
Customer.class,
|
||||
CustomerContractRelation.class
|
||||
};
|
||||
@Test
|
||||
public void baseline(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(entityManager) -> {
|
||||
final Contract contract = new Contract();
|
||||
entityManager.persist( contract );
|
||||
|
||||
final Customer customer = new Customer();
|
||||
entityManager.persist( customer );
|
||||
|
||||
final CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( customer.getId() );
|
||||
customer.addContractRelation( relation );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRelationImplicitFlush() throws Exception {
|
||||
public void addRelationImplicitFlush(EntityManagerFactoryScope scope) {
|
||||
doIt( scope, false );
|
||||
}
|
||||
|
||||
Long contractId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Contract contract = new Contract();
|
||||
private void doIt(EntityManagerFactoryScope scope, boolean explicitFlush) {
|
||||
final Long contractId = scope.fromTransaction(
|
||||
(entityManager) -> {
|
||||
Contract contract = new Contract();
|
||||
|
||||
entityManager.persist( contract );
|
||||
return contract.getId();
|
||||
} );
|
||||
entityManager.persist( contract );
|
||||
return contract.getId();
|
||||
}
|
||||
);
|
||||
|
||||
Long customerId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Customer customer = new Customer();
|
||||
final Long customerId = scope.fromTransaction(
|
||||
(entityManager) -> {
|
||||
Customer customer = new Customer();
|
||||
|
||||
entityManager.persist( customer );
|
||||
return customer.getId();
|
||||
} );
|
||||
entityManager.persist( customer );
|
||||
return customer.getId();
|
||||
}
|
||||
);
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
||||
Customer customer = entityManager.createQuery(
|
||||
"SELECT c " +
|
||||
scope.inTransaction(
|
||||
(entityManager) -> {
|
||||
final String qry = "SELECT c " +
|
||||
"FROM Customer c " +
|
||||
" LEFT JOIN FETCH c.contractRelations " +
|
||||
" WHERE c.id = :customerId", Customer.class )
|
||||
.setParameter( "customerId", customerId )
|
||||
.getSingleResult();
|
||||
" WHERE c.id = :customerId";
|
||||
final Customer customer = entityManager.createQuery( qry, Customer.class )
|
||||
.setParameter( "customerId", customerId )
|
||||
.getSingleResult();
|
||||
|
||||
CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( contractId );
|
||||
customer.addContractRelation( relation );
|
||||
} );
|
||||
final CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( contractId );
|
||||
customer.addContractRelation( relation );
|
||||
|
||||
if ( explicitFlush ) {
|
||||
entityManager.flush();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRelationExplicitFlush() throws Exception {
|
||||
Long contractId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Contract contract = new Contract();
|
||||
|
||||
entityManager.persist( contract );
|
||||
return contract.getId();
|
||||
} );
|
||||
|
||||
Long customerId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Customer customer = new Customer();
|
||||
|
||||
entityManager.persist( customer );
|
||||
return customer.getId();
|
||||
} );
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
|
||||
Customer customer = entityManager.createQuery(
|
||||
"SELECT c " +
|
||||
"FROM Customer c " +
|
||||
" LEFT JOIN FETCH c.contractRelations " +
|
||||
" WHERE c.id = :customerId", Customer.class )
|
||||
.setParameter( "customerId", customerId )
|
||||
.getSingleResult();
|
||||
|
||||
CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( contractId );
|
||||
customer.addContractRelation( relation );
|
||||
|
||||
entityManager.flush();
|
||||
} );
|
||||
public void addRelationExplicitFlush(EntityManagerFactoryScope scope) {
|
||||
doIt( scope, true );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRelationImplicitFlushOneTx() throws Exception {
|
||||
public void addRelationImplicitFlushCloseEntityManager(EntityManagerFactoryScope scope) {
|
||||
final Long contractId = scope.fromTransaction(
|
||||
(entityManager) -> {
|
||||
Contract contract = new Contract();
|
||||
|
||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Contract contract = new Contract();
|
||||
entityManager.persist( contract );
|
||||
return contract.getId();
|
||||
}
|
||||
);
|
||||
|
||||
entityManager.persist( contract );
|
||||
final Long customerId = scope.fromTransaction(
|
||||
(entityManager) -> {
|
||||
Customer customer = new Customer();
|
||||
|
||||
Customer customer = new Customer();
|
||||
|
||||
entityManager.persist( customer );
|
||||
|
||||
customer = entityManager.createQuery(
|
||||
"SELECT c " +
|
||||
"FROM Customer c " +
|
||||
" LEFT JOIN FETCH c.contractRelations " +
|
||||
" WHERE c.id = :customerId", Customer.class )
|
||||
.setParameter( "customerId", customer.getId() )
|
||||
.getSingleResult();
|
||||
|
||||
CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( customer.getId() );
|
||||
customer.addContractRelation( relation );
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addRelationImplicitFlushCloseEntityManager() throws Exception {
|
||||
|
||||
Long contractId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Contract contract = new Contract();
|
||||
|
||||
entityManager.persist( contract );
|
||||
return contract.getId();
|
||||
} );
|
||||
|
||||
Long customerId = doInJPA( this::entityManagerFactory, entityManager -> {
|
||||
Customer customer = new Customer();
|
||||
|
||||
entityManager.persist( customer );
|
||||
return customer.getId();
|
||||
} );
|
||||
entityManager.persist( customer );
|
||||
return customer.getId();
|
||||
}
|
||||
);
|
||||
|
||||
EntityManager entityManager = null;
|
||||
EntityTransaction txn = null;
|
||||
try {
|
||||
entityManager = entityManagerFactory().createEntityManager();
|
||||
entityManager = scope.getEntityManagerFactory().createEntityManager();
|
||||
txn = entityManager.getTransaction();
|
||||
txn.begin();
|
||||
|
||||
Customer customer = entityManager.createQuery(
|
||||
final Customer customer = entityManager.createQuery(
|
||||
"SELECT c " +
|
||||
"FROM Customer c " +
|
||||
" LEFT JOIN FETCH c.contractRelations " +
|
||||
@ -175,7 +151,7 @@ public void addRelationImplicitFlushCloseEntityManager() throws Exception {
|
||||
.setParameter( "customerId", customerId )
|
||||
.getSingleResult();
|
||||
|
||||
CustomerContractRelation relation = new CustomerContractRelation();
|
||||
final CustomerContractRelation relation = new CustomerContractRelation();
|
||||
relation.setContractId( contractId );
|
||||
customer.addContractRelation( relation );
|
||||
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity;
|
||||
package org.hibernate.orm.test.idgen.identity;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.hhh10429;
|
||||
package org.hibernate.orm.test.idgen.identity.hhh10429;
|
||||
|
||||
import org.hibernate.id.IdentityGenerator;
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.identity.hhh10429;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.mapping.KeyValue;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.DomainModelScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Matthew Morrissette
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10429")
|
||||
@DomainModel( annotatedClasses = IdentityGeneratorExtendsTest.EntityBean.class )
|
||||
public class IdentityGeneratorExtendsTest {
|
||||
|
||||
@Test
|
||||
public void testIdentifierGeneratorExtendsIdentityGenerator(DomainModelScope scope) {
|
||||
// the Dialect is irrelevant here.. we just need a Dialect that supports IDENTITY
|
||||
final Dialect dialect = new H2Dialect();
|
||||
|
||||
final MetadataImplementor domainModel = scope.getDomainModel();
|
||||
final PersistentClass entityBinding = domainModel.getEntityBinding( EntityBean.class.getName() );
|
||||
final KeyValue identifier = entityBinding.getIdentifier();
|
||||
|
||||
assertTrue( identifier.isIdentityColumn( domainModel.getIdentifierGeneratorFactory(), dialect ) );
|
||||
}
|
||||
|
||||
@Entity(name = "EntityBean")
|
||||
@Table( name = "entity_bean" )
|
||||
public static class EntityBean {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "customGenerator")
|
||||
@GenericGenerator(name = "customGenerator", strategy = "org.hibernate.orm.test.idgen.identity.hhh10429.CustomIdentityGenerator")
|
||||
private int entityId;
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public void setEntityId(int entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public String description;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.identity.hhh9983;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.dialect.OracleDialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-9983")
|
||||
@RequiresDialect( OracleDialect.class )
|
||||
@DomainModel( annotatedClasses = SaveEntityTest.Company.class )
|
||||
@SessionFactory
|
||||
public class SaveEntityTest {
|
||||
@Test
|
||||
public void testSave(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.save( new Company() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "Company")
|
||||
public static class Company {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
public Company() {
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* @author Andrey Vlasov
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialectFeature( feature = DialectFeatureChecks.SupportsIdentityColumns.class )
|
||||
@DomainModel( annotatedClasses = Sub.class )
|
||||
@SessionFactory
|
||||
public class JoinedSubclassHierarchyWithIdentityGenerationTest {
|
||||
@Test
|
||||
public void shouldPersistDebtorAccountWhenParentServiceAgreementPersisted(SessionFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
(s) -> {
|
||||
s.save( new Sub() );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void cleanTestData(SessionFactoryScope scope) {
|
||||
scope.inTransaction( (s) -> s.createQuery( "delete Sub" ).executeUpdate() );
|
||||
}
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
package org.hibernate.orm.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
package org.hibernate.orm.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
@ -40,8 +40,8 @@ public class DetachAndContainsTest {
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createQuery( "delete from DetachAndContainsTest$Tooth" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from DetachAndContainsTest$Mouth" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from Tooth" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from Mouth" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -72,7 +72,7 @@ public void testDetach(EntityManagerFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Mouth")
|
||||
@Table(name = "mouth")
|
||||
public static class Mouth {
|
||||
@Id
|
||||
@ -82,7 +82,7 @@ public static class Mouth {
|
||||
public Collection<Tooth> teeth;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Tooth")
|
||||
@Table(name = "tooth")
|
||||
public static class Tooth {
|
||||
@Id
|
||||
|
@ -92,7 +92,7 @@ public void testImplicitSequenceGenerator() {
|
||||
|
||||
// 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" ) );
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getName(), is( "my_db_sequence" ) );
|
||||
|
||||
// the JPA defaults since they were not defined
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is( 1 ) );
|
||||
@ -125,30 +125,6 @@ public void testImplicitSequenceGeneratorGeneratorName() {
|
||||
assertThat( sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
@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 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExplicitSequenceGeneratorImplicitNamePreferGeneratorName() {
|
||||
// this should be the default behavior
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.jpa.mapping;
|
||||
|
||||
@ -41,8 +41,8 @@ public class DefaultCascadeTest {
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createQuery( "delete from DefaultCascadeTest$Child" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from DefaultCascadeTest$Parent" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from Child" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from Parent" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -60,7 +60,7 @@ public void testCascadePersist(EntityManagerFactoryScope scope) {
|
||||
);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Parent")
|
||||
@Table(name = "Parent")
|
||||
public static class Parent {
|
||||
|
||||
@ -69,7 +69,7 @@ public static class Parent {
|
||||
private Integer id;
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Child")
|
||||
@Table(name = "Child")
|
||||
public static class Child {
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.jpa.mapping;
|
||||
|
||||
@ -50,7 +50,7 @@ public class UnidirectionalOneToManyIndexColumnTest {
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager -> {
|
||||
entityManager.createQuery( "delete from UnidirectionalOneToManyIndexColumnTest$Parent" ).executeUpdate();
|
||||
entityManager.createQuery( "delete from Parent" ).executeUpdate();
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -88,7 +88,7 @@ public void testRemovingAChild(EntityManagerFactoryScope scope) {
|
||||
}
|
||||
|
||||
|
||||
@Entity
|
||||
@Entity(name = "Parent")
|
||||
@Table(name = "PARENT")
|
||||
public static class Parent {
|
||||
|
||||
@ -117,7 +117,7 @@ public void setChildren(List<Child> children) {
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Entity( name = "Child" )
|
||||
@Table(name = "CHILD")
|
||||
public static class Child {
|
||||
@Id
|
||||
|
@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.biginteger.increment;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BigIntegerIncrementGeneratorTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/biginteger/increment/Mapping.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasics() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Entity entity = new Entity( "BigInteger + increment #1" );
|
||||
s.save( entity );
|
||||
Entity entity2 = new Entity( "BigInteger + increment #2" );
|
||||
s.save( entity2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
assertEquals( BigInteger.valueOf( 1 ), entity.getId() );
|
||||
assertEquals( BigInteger.valueOf( 2 ), entity2.getId() );
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( entity );
|
||||
s.delete( entity2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.biginteger.sequence;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialectFeature( value = DialectChecks.SupportsSequences.class )
|
||||
public class BigIntegerSequenceGeneratorTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/biginteger/sequence/Mapping.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasics() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Entity entity = new Entity( "BigInteger + sequence #1" );
|
||||
s.save( entity );
|
||||
Entity entity2 = new Entity( "BigInteger + sequence #2" );
|
||||
s.save( entity2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
// hsqldb defines different behavior for the initial select from a sequence
|
||||
// then say oracle
|
||||
// assertEquals( BigInteger.valueOf( 1 ), entity.getId() );
|
||||
// assertEquals( BigInteger.valueOf( 2 ), entity2.getId() );
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.delete( entity );
|
||||
s.delete( entity2 );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
package org.hibernate.test.idgen.biginteger.sequence;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
||||
/**
|
||||
* This test explicitly maps scale="0" for the sequence column. It works around the arithmetic
|
||||
* overflow that happens because the generated column cannot accommodate the SQL Server
|
||||
* sequence that starts, by default, with the value, -9,223,372,036,854,775,808.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
@RequiresDialectFeature( value = DialectChecks.SupportsSequences.class )
|
||||
public class BigIntegerSequenceGeneratorZeroScaleTest extends BigIntegerSequenceGeneratorTest {
|
||||
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/biginteger/sequence/ZeroScaleMapping.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-9250")
|
||||
public void testBasics() {
|
||||
super.testBasics();
|
||||
}
|
||||
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.auto;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.dialect.H2Dialect;
|
||||
import org.hibernate.id.enhanced.DatabaseStructure;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.tool.schema.Action;
|
||||
|
||||
import org.hibernate.testing.FailureExpected;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class NewGeneratorsTests extends BaseUnitTestCase {
|
||||
@Test
|
||||
@FailureExpected(
|
||||
jiraKey = "HHH-14491",
|
||||
message = "To be implemented for 6; see https://github.com/hibernate/hibernate-orm/discussions/3809"
|
||||
)
|
||||
public void testAutoDefaults() {
|
||||
// check that `@GeneratedValue(AUTO)` with no explicit generator applies
|
||||
// various defaults:
|
||||
// - allocation/increment size = 50
|
||||
// - sequence-per-entity with a suffix
|
||||
|
||||
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder();
|
||||
ssrb.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP );
|
||||
|
||||
final StandardServiceRegistry ssr = ssrb.build();
|
||||
final Metadata metadata = new MetadataSources( ssr )
|
||||
.addAnnotatedClass( Entity1.class )
|
||||
.buildMetadata();
|
||||
|
||||
final DefaultIdentifierGeneratorFactory generatorFactory = new DefaultIdentifierGeneratorFactory();
|
||||
generatorFactory.injectServices( (ServiceRegistryImplementor) ssr );
|
||||
|
||||
final PersistentClass entityBinding = metadata.getEntityBinding( Entity1.class.getName() );
|
||||
final SequenceStyleGenerator generator = (SequenceStyleGenerator) entityBinding.getRootClass().getIdentifier().createIdentifierGenerator(
|
||||
generatorFactory,
|
||||
new H2Dialect(),
|
||||
"",
|
||||
"",
|
||||
entityBinding.getRootClass()
|
||||
);
|
||||
|
||||
final DatabaseStructure databaseStructure = generator.getDatabaseStructure();
|
||||
|
||||
// HHH-14491 - what we want to happen
|
||||
assertThat( databaseStructure.getName(), is( "Entity1_SEQ" ) );
|
||||
// or this depending on the discussion (Jira) about using entity name v. table name as the base
|
||||
assertThat( databaseStructure.getName(), is( "tbl_1_SEQ" ) );
|
||||
|
||||
// HHH-14491 - this is what we want to have happen
|
||||
assertThat( databaseStructure.getIncrementSize(), is( 50 ) );
|
||||
}
|
||||
|
||||
@Entity( name = "Entity1" )
|
||||
@Table( name = "tbl_1" )
|
||||
public static class Entity1 {
|
||||
@Id
|
||||
@GeneratedValue( strategy = GenerationType.AUTO )
|
||||
private Integer id;
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.forcedtable;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.NoopOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/forcedtable/Basic.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
);
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertTrue(
|
||||
"table structure was not used",
|
||||
TableStructure.class.isInstance( generator.getDatabaseStructure() )
|
||||
);
|
||||
assertTrue(
|
||||
"no-op optimizer was not used",
|
||||
NoopOptimizer.class.isInstance( generator.getOptimizer() )
|
||||
);
|
||||
|
||||
int count = 5;
|
||||
Entity[] entities = new Entity[count];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entities[i].getId().longValue() );
|
||||
assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.forcedtable;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HiLoForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/forcedtable/HiLo.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
);
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertTrue(
|
||||
"table structure was not used",
|
||||
TableStructure.class.isInstance( generator.getDatabaseStructure() )
|
||||
);
|
||||
assertTrue(
|
||||
"hilo optimizer was not used",
|
||||
HiLoOptimizer.class.isInstance( generator.getOptimizer() )
|
||||
);
|
||||
HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 1 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entities[i].getId().longValue() );
|
||||
assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[ increment ] = new Entity( "" + increment );
|
||||
s.save( entities[ increment ] );
|
||||
long expectedId = optimizer.getIncrementSize() + 1;
|
||||
assertEquals( expectedId, entities[ optimizer.getIncrementSize() ].getId().longValue() );
|
||||
assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization + clock-over
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.forcedtable;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.id.enhanced.TableStructure;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PooledForcedTableSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/forcedtable/Pooled.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertTrue(
|
||||
"sequence style generator was not used",
|
||||
SequenceStyleGenerator.class.isInstance( persister.getIdentifierGenerator() )
|
||||
);
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertTrue(
|
||||
"table structure was not used",
|
||||
TableStructure.class.isInstance( generator.getDatabaseStructure() )
|
||||
);
|
||||
assertTrue(
|
||||
"pooled optimizer was not used",
|
||||
PooledOptimizer.class.isInstance( generator.getOptimizer() )
|
||||
);
|
||||
PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 2 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entities[i].getId().longValue() );
|
||||
// NOTE : initialization calls table twice
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[increment + 1] = new Entity( "" + increment );
|
||||
s.save( entities[increment + 1] );
|
||||
long expectedId = optimizer.getIncrementSize() + 2;
|
||||
assertEquals( expectedId, entities[ increment + 1 ].getId().longValue() );
|
||||
// initialization (2) + clock over
|
||||
assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.sequence;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
|
||||
*/
|
||||
public class BasicSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/sequence/Basic.hbm.xml", "idgen/enhanced/sequence/Dedicated.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
|
||||
int count = 5;
|
||||
Entity[] entities = new Entity[count];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entities[i].getId().longValue() );
|
||||
assertEquals( expectedId, generator.getDatabaseStructure().getTimesAccessed() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-6790")
|
||||
public void testSequencePerEntity() {
|
||||
final String overriddenEntityName = "SpecialEntity";
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( overriddenEntityName );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertEquals( overriddenEntityName + SequenceStyleGenerator.DEF_SEQUENCE_SUFFIX, generator.getDatabaseStructure().getName() );
|
||||
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
Entity entity1 = new Entity( "1" );
|
||||
s.save( overriddenEntityName, entity1 );
|
||||
Entity entity2 = new Entity( "2" );
|
||||
s.save( overriddenEntityName, entity2 );
|
||||
s.getTransaction().commit();
|
||||
|
||||
assertEquals( 1, entity1.getId().intValue() );
|
||||
assertEquals( 2, entity2.getId().intValue() );
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.sequence;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.annotations.Parameter;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.id.SequenceMismatchStrategy;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Nathan Xu
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-13783")
|
||||
@RequiresDialectFeature(DialectChecks.SupportsSequences.class)
|
||||
public class HiLoSequenceMismatchStrategyTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
public final static String sequenceName = "ID_SEQ_HILO_SEQ";
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[]{ TestEntity.class };
|
||||
}
|
||||
|
||||
protected void configure(Configuration configuration) {
|
||||
configuration.setProperty(
|
||||
AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY,
|
||||
SequenceMismatchStrategy.EXCEPTION.toString() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void afterConfigurationBuilt(Configuration configuration) {
|
||||
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
|
||||
connectionProvider.configure( Environment.getProperties() );
|
||||
|
||||
String[] dropSequenceStatements = getDialect().getDropSequenceStrings( sequenceName );
|
||||
String[] createSequenceStatements = getDialect().getCreateSequenceStrings( sequenceName, 1, 1 );
|
||||
|
||||
try ( Connection connection = connectionProvider.getConnection();
|
||||
Statement statement = connection.createStatement() ) {
|
||||
|
||||
for ( String dropSequenceStatement : dropSequenceStatements ) {
|
||||
try {
|
||||
statement.execute( dropSequenceStatement );
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
for ( String createSequenceStatement : createSequenceStatements ) {
|
||||
statement.execute( createSequenceStatement );
|
||||
}
|
||||
connection.commit();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
fail( e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSequenceMismatchStrategyNotApplied() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( TestEntity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
|
||||
SequenceStyleGenerator generator = (SequenceStyleGenerator) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
||||
|
||||
String sequenceName = generator.getDatabaseStructure().getName();
|
||||
Assert.assertEquals( this.sequenceName, sequenceName );
|
||||
|
||||
int incrementSize = generator.getOptimizer().getIncrementSize();
|
||||
Assert.assertNotEquals( 1, incrementSize );
|
||||
}
|
||||
|
||||
@Entity(name = "TestEntity")
|
||||
public static class TestEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hilo_sequence_generator")
|
||||
@GenericGenerator(name = "hilo_sequence_generator", strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator", parameters = {
|
||||
@Parameter(name = "sequence_name", value = sequenceName),
|
||||
@Parameter(name = "initial_value", value = "1"),
|
||||
@Parameter(name = "increment_size", value = "10"),
|
||||
@Parameter(name = "optimizer", value = "hilo")
|
||||
})
|
||||
private Long id;
|
||||
|
||||
private String aString;
|
||||
}
|
||||
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.sequence;
|
||||
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HiLoSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
protected String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/sequence/HiLo.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
||||
HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 1 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
assertEquals( 1, generator.getDatabaseStructure().getTimesAccessed() ); // initialization
|
||||
assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[ increment ] = new Entity( "" + increment );
|
||||
s.save( entities[ increment ] );
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization
|
||||
assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.sequence;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PooledSequenceTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/sequence/Pooled.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( SequenceStyleGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
SequenceStyleGenerator generator = ( SequenceStyleGenerator ) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 2 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
assertEquals( 2, generator.getDatabaseStructure().getTimesAccessed() ); // initialization calls seq twice
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization calls seq twice
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[ increment + 1 ] = new Entity( "" + increment );
|
||||
s.save( entities[ increment + 1 ] );
|
||||
assertEquals( 3, generator.getDatabaseStructure().getTimesAccessed() ); // initialization (2) + clock over
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization (2) + clock over
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class BasicTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/table/Basic.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
TableGenerator generator = ( TableGenerator ) persister.getIdentifierGenerator();
|
||||
|
||||
int count = 5;
|
||||
Entity[] entities = new Entity[count];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
long expectedId = i + 1;
|
||||
assertEquals( expectedId, entities[i].getId().longValue() );
|
||||
assertEquals( expectedId, generator.getTableAccessCount() );
|
||||
assertEquals( expectedId, ( (BasicHolder) generator.getOptimizer().getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.enhanced.HiLoOptimizer;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class HiLoTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/table/HiLo.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
TableGenerator generator = ( TableGenerator ) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( HiLoOptimizer.class, generator.getOptimizer().getClass() );
|
||||
HiLoOptimizer optimizer = (HiLoOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 1 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
assertEquals( 1, generator.getTableAccessCount() ); // initialization
|
||||
assertEquals( 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[ increment ] = new Entity( "" + increment );
|
||||
s.save( entities[ increment ] );
|
||||
assertEquals( 2, generator.getTableAccessCount() ); // initialization
|
||||
assertEquals( 2, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getHiValue() ).getActualLongValue() );
|
||||
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.enhanced.table;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.id.enhanced.PooledOptimizer;
|
||||
import org.hibernate.id.enhanced.TableGenerator;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
import static org.hibernate.id.IdentifierGeneratorHelper.BasicHolder;
|
||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertClassAssignability;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class PooledTableTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
public String[] getMappings() {
|
||||
return new String[] { "idgen/enhanced/table/Pooled.hbm.xml" };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNormalBoundary() {
|
||||
EntityPersister persister = sessionFactory().getEntityPersister( Entity.class.getName() );
|
||||
assertClassAssignability( TableGenerator.class, persister.getIdentifierGenerator().getClass() );
|
||||
TableGenerator generator = ( TableGenerator ) persister.getIdentifierGenerator();
|
||||
assertClassAssignability( PooledOptimizer.class, generator.getOptimizer().getClass() );
|
||||
PooledOptimizer optimizer = (PooledOptimizer) generator.getOptimizer();
|
||||
|
||||
int increment = optimizer.getIncrementSize();
|
||||
Entity[] entities = new Entity[ increment + 2 ];
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i <= increment; i++ ) {
|
||||
entities[i] = new Entity( "" + ( i + 1 ) );
|
||||
s.save( entities[i] );
|
||||
assertEquals( 2, generator.getTableAccessCount() ); // initialization calls seq twice
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization calls seq twice
|
||||
assertEquals( i + 1, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
assertEquals( increment + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() );
|
||||
}
|
||||
// now force a "clock over"
|
||||
entities[ increment + 1 ] = new Entity( "" + increment );
|
||||
s.save( entities[ increment + 1 ] );
|
||||
assertEquals( 3, generator.getTableAccessCount() ); // initialization (2) + clock over
|
||||
assertEquals( ( increment * 2 ) + 1, ( (BasicHolder) optimizer.getLastSourceValue() ).getActualLongValue() ); // initialization (2) + clock over
|
||||
assertEquals( increment + 2, ( (BasicHolder) optimizer.getLastValue() ).getActualLongValue() );
|
||||
s.getTransaction().commit();
|
||||
|
||||
s.beginTransaction();
|
||||
for ( int i = 0; i < entities.length; i++ ) {
|
||||
assertEquals( i + 1, entities[i].getId().intValue() );
|
||||
s.delete( entities[i] );
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.foreign;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.Environment;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.jta.TestingJtaBootstrap;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-12738")
|
||||
public class ForeignGeneratorJtaTest extends ForeignGeneratorResourceLocalTest {
|
||||
|
||||
@Override
|
||||
protected void addConfigOptions(Map options) {
|
||||
TestingJtaBootstrap.prepare( options );
|
||||
options.put( Environment.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.hhh10429;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataBuilder;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.model.relational.Namespace;
|
||||
import org.hibernate.mapping.KeyValue;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Matthew Morrissette
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-10429")
|
||||
@RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
|
||||
public class IdentityGeneratorExtendsTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Entity(name = "EntityBean")
|
||||
@Table
|
||||
public static class EntityBean {
|
||||
|
||||
@Id
|
||||
@Column
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "customGenerator")
|
||||
@GenericGenerator(name = "customGenerator", strategy = "org.hibernate.test.idgen.identity.hhh10429.CustomIdentityGenerator")
|
||||
private int entityId;
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public void setEntityId(int entityId) {
|
||||
this.entityId = entityId;
|
||||
}
|
||||
|
||||
public String description;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {EntityBean.class};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdentifierGeneratorExtendsIdentityGenerator() {
|
||||
final MetadataSources sources = new MetadataSources( serviceRegistry() );
|
||||
sources.addAnnotatedClass( EntityBean.class );
|
||||
|
||||
final MetadataBuilder builder = sources.getMetadataBuilder();
|
||||
final Metadata metadata = builder.build();
|
||||
|
||||
|
||||
for ( final Namespace ns : metadata.getDatabase().getNamespaces() ) {
|
||||
for ( final org.hibernate.mapping.Table table : ns.getTables() ) {
|
||||
final KeyValue value = table.getIdentifierValue();
|
||||
assertNotNull( "IdentifierValue was null", value );
|
||||
assertTrue( value.isIdentityColumn( metadata.getIdentifierGeneratorFactory(), getDialect() ) );
|
||||
}
|
||||
}
|
||||
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.save( new EntityBean() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: Apache License, Version 2.0
|
||||
* See the LICENSE file in the root directory or visit http://www.apache.org/licenses/LICENSE-2.0
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.hhh9983;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.dialect.Oracle12cDialect;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.RequiresDialect;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-9983")
|
||||
@RequiresDialect(Oracle12cDialect.class)
|
||||
public class SaveEntityTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {Company.class};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSave() {
|
||||
Session s = openSession();
|
||||
Transaction transaction = s.beginTransaction();
|
||||
try {
|
||||
s.save( new Company() );
|
||||
s.getTransaction().commit();
|
||||
}
|
||||
finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
@Table(name = "Company")
|
||||
public class Company {
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
public Company() {
|
||||
}
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.identity.joinedSubClass;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.DialectChecks;
|
||||
import org.hibernate.testing.RequiresDialectFeature;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* @author Andrey Vlasov
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@RequiresDialectFeature( DialectChecks.SupportsIdentityColumns.class )
|
||||
public class JoinedSubclassHierarchyWithIdentityGenerationTest extends BaseCoreFunctionalTestCase {
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { Sub.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPersistDebtorAccountWhenParentServiceAgreementPersisted() {
|
||||
Session s = openSession();
|
||||
s.beginTransaction();
|
||||
s.save( new Sub() );
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
s.beginTransaction();
|
||||
s.createQuery( "delete Sub" ).executeUpdate();
|
||||
s.getTransaction().commit();
|
||||
s.close();
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.namescope;
|
||||
|
||||
import java.util.Properties;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class IdGeneratorNamesGlobalScopeTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoSequenceGenratorNameClash() {
|
||||
buildSessionFactory();
|
||||
}
|
||||
|
||||
@Entity(name = "FirstEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier_2",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5
|
||||
)
|
||||
public static class FirstEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@Entity(name = "SecondEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5
|
||||
)
|
||||
public static class SecondEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
}
|
||||
|
||||
private void buildSessionFactory() {
|
||||
Configuration configuration = new Configuration();
|
||||
final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder();
|
||||
builder.applyClassLoader( getClass().getClassLoader() );
|
||||
BootstrapServiceRegistry bootRegistry = builder.build();
|
||||
StandardServiceRegistryImpl serviceRegistry = buildServiceRegistry( bootRegistry, configuration );
|
||||
configuration.addAnnotatedClass( FirstEntity.class );
|
||||
configuration.addAnnotatedClass( SecondEntity.class );
|
||||
configuration.buildSessionFactory( serviceRegistry );
|
||||
}
|
||||
|
||||
protected StandardServiceRegistryImpl buildServiceRegistry(BootstrapServiceRegistry bootRegistry, Configuration configuration) {
|
||||
Properties properties = new Properties();
|
||||
properties.putAll( configuration.getProperties() );
|
||||
properties.put( AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE, "true" );
|
||||
ConfigurationHelper.resolvePlaceHolders( properties );
|
||||
|
||||
StandardServiceRegistryBuilder cfgRegistryBuilder = configuration.getStandardServiceRegistryBuilder();
|
||||
|
||||
StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder( bootRegistry, cfgRegistryBuilder.getAggregatedCfgXml() )
|
||||
.applySettings( properties );
|
||||
|
||||
return (StandardServiceRegistryImpl) registryBuilder.build();
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.idgen.namescope;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andrea Boriero
|
||||
*/
|
||||
public class IdGeneratorNamesLocalScopeTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] { FirstEntity.class, SecondEntity.class };
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSequenceGenratorNameClash() {
|
||||
final FirstEntity first = new FirstEntity();
|
||||
final SecondEntity second = new SecondEntity();
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
session.persist( first );
|
||||
session.persist( second );
|
||||
} );
|
||||
|
||||
assertThat( first.getId(), is( 2L ) );
|
||||
assertThat( second.getId(), is( 11L ) );
|
||||
}
|
||||
|
||||
@Entity(name = "FirstEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier_2",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5,
|
||||
initialValue = 1
|
||||
)
|
||||
public static class FirstEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@Entity(name = "SecondEntity")
|
||||
@TableGenerator(
|
||||
name = "table-generator",
|
||||
table = "table_identifier",
|
||||
pkColumnName = "identifier",
|
||||
valueColumnName = "value",
|
||||
allocationSize = 5,
|
||||
initialValue = 10
|
||||
)
|
||||
public static class SecondEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.TABLE, generator = "table-generator")
|
||||
private Long id;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestingJtaPlatformImpl extends AbstractJtaPlatform {
|
||||
public static final String NAME = TestingJtaPlatformImpl.class.getName();
|
||||
public static final TestingJtaPlatformImpl INSTANCE = new TestingJtaPlatformImpl();
|
||||
|
||||
private final TransactionManager transactionManager;
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.testing.jta;
|
||||
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinatorOwner;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class TestingJtaTransactionCoordinatorBuilder implements TransactionCoordinatorBuilder {
|
||||
@Override
|
||||
public TransactionCoordinator buildTransactionCoordinator(TransactionCoordinatorOwner owner, Options options) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isJta() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PhysicalConnectionHandlingMode getDefaultConnectionHandlingMode() {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user