From 030f442f3cd894ff9defff62ac3b0eecc39d9d83 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 19 Apr 2016 13:40:00 +0100 Subject: [PATCH] HHH-10372 - Fix Sequence generator for idbag ignores generator parameters --- .../model/IdentifierGeneratorDefinition.java | 6 ++++++ .../source/internal/hbm/ModelBinder.java | 2 +- .../hbm/PluralAttributeSourceIdBagImpl.java | 21 +++++++++++++++++-- .../model/source/spi/CollectionIdSource.java | 7 +++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java index c8c91cebab..8039250c01 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/IdentifierGeneratorDefinition.java @@ -39,6 +39,12 @@ public class IdentifierGeneratorDefinition implements Serializable { } } + public IdentifierGeneratorDefinition( + final String name, + final Map parameters) { + this( name, name, parameters ); + } + public IdentifierGeneratorDefinition(String name) { this( name, name ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java index 8f70b0d9f0..ad518d87a8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/ModelBinder.java @@ -3386,7 +3386,7 @@ public class ModelBinder { makeIdentifier( mappingDocument, - new IdentifierGeneratorDefinition( idSource.getGeneratorName() ), + new IdentifierGeneratorDefinition( idSource.getGeneratorName(), idSource.getParameters() ), null, idBinding ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeSourceIdBagImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeSourceIdBagImpl.java index df4bf1348d..1d8b88b800 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeSourceIdBagImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/PluralAttributeSourceIdBagImpl.java @@ -6,8 +6,10 @@ */ package org.hibernate.boot.model.source.internal.hbm; +import java.util.Collections; import java.util.List; import java.util.Locale; +import java.util.Map; import org.hibernate.boot.MappingException; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmIdBagCollectionType; @@ -19,6 +21,7 @@ import org.hibernate.boot.model.source.spi.PluralAttributeNature; import org.hibernate.boot.model.source.spi.RelationalValueSource; import org.hibernate.boot.model.source.spi.SizeSource; import org.hibernate.internal.util.StringHelper; +import org.hibernate.internal.util.collections.CollectionHelper; /** * @author Steve Ebersole @@ -81,10 +84,12 @@ public class PluralAttributeSourceIdBagImpl extends AbstractPluralAttributeSourc ); } + this.collectionIdSource = new CollectionIdSourceImpl( (ColumnSource) collectionIdRelationalValueSource, new HibernateTypeSourceImpl( idBagMapping.getCollectionId().getType() ), - idBagMapping.getCollectionId().getGenerator().getClazz() + idBagMapping.getCollectionId().getGenerator().getClazz(), + Helper.extractParameters( idBagMapping.getCollectionId().getGenerator().getConfigParameters() ) ); } @@ -122,14 +127,22 @@ public class PluralAttributeSourceIdBagImpl extends AbstractPluralAttributeSourc private final ColumnSource columnSource; private final HibernateTypeSourceImpl typeSource; private final String generator; + private final Map parameters; public CollectionIdSourceImpl( ColumnSource columnSource, HibernateTypeSourceImpl typeSource, - String generator) { + String generator, + final Map parameters) { this.columnSource = columnSource; this.typeSource = typeSource; this.generator = generator; + if ( CollectionHelper.isEmpty( parameters ) ) { + this.parameters = Collections.emptyMap(); + } + else { + this.parameters = Collections.unmodifiableMap( parameters ); + } } @Override @@ -146,5 +159,9 @@ public class PluralAttributeSourceIdBagImpl extends AbstractPluralAttributeSourc public String getGeneratorName() { return generator; } + + public Map getParameters() { + return parameters; + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/CollectionIdSource.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/CollectionIdSource.java index 9fa9febb96..ee5c35434c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/CollectionIdSource.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/spi/CollectionIdSource.java @@ -6,6 +6,8 @@ */ package org.hibernate.boot.model.source.spi; +import java.util.Map; + /** * @author Steve Ebersole */ @@ -30,4 +32,9 @@ public interface CollectionIdSource { * @return The identifier value generator name */ public String getGeneratorName(); + + /** + * @return The identifier generator configuration parameters + */ + public Map getParameters(); }