HHH-10013 - Adjust default for hibernate.id.new_generator_mappings to true
This commit is contained in:
parent
41836726e1
commit
f8b523f3de
|
@ -191,8 +191,8 @@
|
||||||
The discussions below assume that the application is using Hibernate's "new generator mappings" as
|
The discussions below assume that the application is using Hibernate's "new generator mappings" as
|
||||||
indicated by the <literal>hibernate.id.new_generator_mappings</literal> setting or
|
indicated by the <literal>hibernate.id.new_generator_mappings</literal> setting or
|
||||||
<methodname>MetadataBuilder.enableNewIdentifierGeneratorSupport</methodname> method during bootstrap.
|
<methodname>MetadataBuilder.enableNewIdentifierGeneratorSupport</methodname> method during bootstrap.
|
||||||
For legacy reasons the default value for this setting is currently false, however we anticipate it
|
This is set to true by default, however if applications set this to false the resolutions discussed
|
||||||
becoming true at some point. The rest of the discussion here assumes this setting is enabled (true).
|
here will be very different. The rest of the discussion here assumes this setting is enabled (true).
|
||||||
</para>
|
</para>
|
||||||
</note>
|
</note>
|
||||||
|
|
||||||
|
|
|
@ -686,7 +686,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
||||||
final boolean useNewIdentifierGenerators = configService.getSetting(
|
final boolean useNewIdentifierGenerators = configService.getSetting(
|
||||||
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
|
AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
|
||||||
StandardConverters.BOOLEAN,
|
StandardConverters.BOOLEAN,
|
||||||
false
|
true
|
||||||
);
|
);
|
||||||
if ( useNewIdentifierGenerators ) {
|
if ( useNewIdentifierGenerators ) {
|
||||||
idGenerationTypeInterpreter.disableLegacyFallback();
|
idGenerationTypeInterpreter.disableLegacyFallback();
|
||||||
|
|
|
@ -256,7 +256,9 @@ public interface AvailableSettings {
|
||||||
/**
|
/**
|
||||||
* Setting which indicates whether or not the new {@link org.hibernate.id.IdentifierGenerator} are used
|
* Setting which indicates whether or not the new {@link org.hibernate.id.IdentifierGenerator} are used
|
||||||
* for AUTO, TABLE and SEQUENCE.
|
* for AUTO, TABLE and SEQUENCE.
|
||||||
* Default to false to keep backward compatibility.
|
* <p/>
|
||||||
|
* Default is {@code true}. Existing applications may want to disable this (set it {@code false}) for
|
||||||
|
* upgrade compatibility.
|
||||||
*
|
*
|
||||||
* @see MetadataBuilder#enableNewIdentifierGeneratorSupport
|
* @see MetadataBuilder#enableNewIdentifierGeneratorSupport
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -731,9 +731,6 @@ public abstract class Dialect implements ConversionContext {
|
||||||
if ( supportsIdentityColumns() ) {
|
if ( supportsIdentityColumns() ) {
|
||||||
return IdentityGenerator.class;
|
return IdentityGenerator.class;
|
||||||
}
|
}
|
||||||
else if ( supportsSequences() ) {
|
|
||||||
return SequenceGenerator.class;
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
return SequenceStyleGenerator.class;
|
return SequenceStyleGenerator.class;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||||
import org.hibernate.hql.spi.id.local.AfterUseAction;
|
import org.hibernate.hql.spi.id.local.AfterUseAction;
|
||||||
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
|
import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy;
|
||||||
import org.hibernate.id.SequenceGenerator;
|
import org.hibernate.id.SequenceGenerator;
|
||||||
|
import org.hibernate.id.enhanced.SequenceStyleGenerator;
|
||||||
import org.hibernate.internal.util.JdbcExceptionHelper;
|
import org.hibernate.internal.util.JdbcExceptionHelper;
|
||||||
import org.hibernate.procedure.internal.PostgresCallableStatementSupport;
|
import org.hibernate.procedure.internal.PostgresCallableStatementSupport;
|
||||||
import org.hibernate.procedure.spi.CallableStatementSupport;
|
import org.hibernate.procedure.spi.CallableStatementSupport;
|
||||||
|
@ -313,7 +314,7 @@ public class PostgreSQL81Dialect extends Dialect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getNativeIdentifierGeneratorClass() {
|
public Class getNativeIdentifierGeneratorClass() {
|
||||||
return SequenceGenerator.class;
|
return SequenceStyleGenerator.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class DefaultIdentifierGeneratorFactory
|
||||||
register( "assigned", Assigned.class );
|
register( "assigned", Assigned.class );
|
||||||
register( "identity", IdentityGenerator.class );
|
register( "identity", IdentityGenerator.class );
|
||||||
register( "select", SelectGenerator.class );
|
register( "select", SelectGenerator.class );
|
||||||
register( "sequence", SequenceGenerator.class );
|
register( "sequence", SequenceStyleGenerator.class );
|
||||||
register( "seqhilo", SequenceHiLoGenerator.class );
|
register( "seqhilo", SequenceHiLoGenerator.class );
|
||||||
register( "increment", IncrementGenerator.class );
|
register( "increment", IncrementGenerator.class );
|
||||||
register( "foreign", ForeignGenerator.class );
|
register( "foreign", ForeignGenerator.class );
|
||||||
|
|
|
@ -22,6 +22,14 @@ public abstract class AbstractHHH3949TestTask extends AbstractEnhancerTestTask {
|
||||||
Session session = getFactory().openSession();
|
Session session = getFactory().openSession();
|
||||||
Transaction tx = session.beginTransaction();
|
Transaction tx = session.beginTransaction();
|
||||||
|
|
||||||
|
// it is important that the data associations remain as follows:
|
||||||
|
// * Johnny <-> Volkswagen Golf
|
||||||
|
// * Ricky <-> Subaru Impreza
|
||||||
|
// * Rosy -> none
|
||||||
|
// * none <- Renault Truck
|
||||||
|
//
|
||||||
|
// see #shouldHaveVehicle and #shouldHaveDriver
|
||||||
|
|
||||||
Person person1 = new Person( "Johnny" );
|
Person person1 = new Person( "Johnny" );
|
||||||
Person person2 = new Person( "Ricky" );
|
Person person2 = new Person( "Ricky" );
|
||||||
Person person3 = new Person( "Rosy" );
|
Person person3 = new Person( "Rosy" );
|
||||||
|
@ -46,6 +54,16 @@ public abstract class AbstractHHH3949TestTask extends AbstractEnhancerTestTask {
|
||||||
session.close();
|
session.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean shouldHaveVehicle(Person person) {
|
||||||
|
return "Johnny".equals( person.getName() )
|
||||||
|
|| "Ricky".equals( person.getName() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean shouldHaveDriver(Vehicle vehicle) {
|
||||||
|
return "Volkswagen Golf".equals( vehicle.getName() )
|
||||||
|
|| "Subaru Impreza".equals( vehicle.getName() );
|
||||||
|
}
|
||||||
|
|
||||||
protected void cleanup() {
|
protected void cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class HHH3949TestTask1 extends AbstractHHH3949TestTask {
|
||||||
// 4) verify the results
|
// 4) verify the results
|
||||||
for ( Person person : persons ) {
|
for ( Person person : persons ) {
|
||||||
assertTrue( Hibernate.isInitialized( person ) );
|
assertTrue( Hibernate.isInitialized( person ) );
|
||||||
if ( person.getId() < 3 ) {
|
if ( shouldHaveVehicle( person ) ) {
|
||||||
assertNotNull( person.getVehicle() );
|
assertNotNull( person.getVehicle() );
|
||||||
assertTrue( Hibernate.isInitialized( person.getVehicle() ) );
|
assertTrue( Hibernate.isInitialized( person.getVehicle() ) );
|
||||||
assertNotNull( person.getVehicle().getDriver() );
|
assertNotNull( person.getVehicle().getDriver() );
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class HHH3949TestTask2 extends AbstractHHH3949TestTask {
|
||||||
|
|
||||||
// 4) verify the results
|
// 4) verify the results
|
||||||
for ( Vehicle vehicle : vehicles ) {
|
for ( Vehicle vehicle : vehicles ) {
|
||||||
if ( vehicle.getId() < 3 ) {
|
if ( shouldHaveDriver( vehicle ) ) {
|
||||||
Assert.assertNotNull( vehicle.getDriver() );
|
Assert.assertNotNull( vehicle.getDriver() );
|
||||||
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
|
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class HHH3949TestTask3 extends AbstractHHH3949TestTask {
|
||||||
.setFetchMode( "vehicle", FetchMode.JOIN )
|
.setFetchMode( "vehicle", FetchMode.JOIN )
|
||||||
.list();
|
.list();
|
||||||
for ( Person person : persons ) {
|
for ( Person person : persons ) {
|
||||||
if ( person.getId() < 3 ) {
|
if ( shouldHaveVehicle( person ) ) {
|
||||||
Assert.assertNotNull( person.getVehicle() );
|
Assert.assertNotNull( person.getVehicle() );
|
||||||
Assert.assertNotNull( person.getVehicle().getDriver() );
|
Assert.assertNotNull( person.getVehicle().getDriver() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class HHH3949TestTask4 extends AbstractHHH3949TestTask {
|
||||||
session.close();
|
session.close();
|
||||||
|
|
||||||
for ( Vehicle vehicle : vehicles ) {
|
for ( Vehicle vehicle : vehicles ) {
|
||||||
if ( vehicle.getId() < 3 ) {
|
if ( shouldHaveDriver( vehicle ) ) {
|
||||||
Assert.assertNotNull( vehicle.getDriver() );
|
Assert.assertNotNull( vehicle.getDriver() );
|
||||||
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
|
Assert.assertNotNull( vehicle.getDriver().getVehicle() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,8 @@ Working list of changes for 5.0
|
||||||
* For EnumType mappings defined in hbm.xml where the user wants name-mapping (`javax.persistence.EnumType#STRING`)
|
* For EnumType mappings defined in hbm.xml where the user wants name-mapping (`javax.persistence.EnumType#STRING`)
|
||||||
the configuration must explicitly state that using either the `useNamed` (true) setting or by specifying the `type`
|
the configuration must explicitly state that using either the `useNamed` (true) setting or by specifying the `type`
|
||||||
setting set to the value 12 (VARCHAR JDBC type code).
|
setting set to the value 12 (VARCHAR JDBC type code).
|
||||||
|
* Default value for `hibernate.id.new_generator_mappings` setting changed to true for 5.0. See
|
||||||
|
`org.hibernate.cfg.AvailableSettings#USE_NEW_ID_GENERATOR_MAPPINGS` javadocs.
|
||||||
|
|
||||||
|
|
||||||
TODOs
|
TODOs
|
||||||
|
|
Loading…
Reference in New Issue