From 513c2358f7fea16fa69f2fc4eeb472b54ac49dd0 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 18 Apr 2016 11:31:38 +0100 Subject: [PATCH] HHH-10693 - Fix PostgreSQL should not use nvarchar when using Nationaliztaion --- .../cfg/annotations/SimpleValueBinder.java | 16 ++++++++++++++-- .../main/java/org/hibernate/dialect/Dialect.java | 9 +++++++++ .../hibernate/dialect/PostgreSQL81Dialect.java | 5 +++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java index e01b689a08..6da3198707 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java @@ -39,6 +39,8 @@ import org.hibernate.cfg.Ejb3JoinColumn; import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass; import org.hibernate.cfg.SetSimpleValueTypeSecondPass; +import org.hibernate.dialect.Dialect; +import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.SimpleValue; @@ -150,8 +152,10 @@ public class SimpleValueBinder { typeParameters.clear(); String type = BinderHelper.ANNOTATION_STRING_DEFAULT; - isNationalized = property.isAnnotationPresent( Nationalized.class ) - || buildingContext.getBuildingOptions().useNationalizedCharacterData(); + if ( getDialect().supportsNationalizedTypes() ) { + isNationalized = property.isAnnotationPresent( Nationalized.class ) + || buildingContext.getBuildingOptions().useNationalizedCharacterData(); + } Type annType = null; if ( (!key && property.isAnnotationPresent( Type.class )) @@ -307,6 +311,14 @@ public class SimpleValueBinder { applyAttributeConverter( property, attributeConverterDescriptor ); } + private Dialect getDialect() { + return buildingContext.getBuildingOptions() + .getServiceRegistry() + .getService( JdbcServices.class ) + .getJdbcEnvironment() + .getDialect(); + } + private void applyAttributeConverter(XProperty property, AttributeConverterDescriptor attributeConverterDescriptor) { if ( attributeConverterDescriptor == null ) { return; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 2eff91bfaa..ea55b0a6da 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -2850,4 +2850,13 @@ public abstract class Dialect implements ConversionContext { public boolean supportsNamedParameters(DatabaseMetaData databaseMetaData) throws SQLException { return databaseMetaData != null && databaseMetaData.supportsNamedParameters(); } + + /** + * Does this dialect supports Nationalized Types + * + * @return boolean + */ + public boolean supportsNationalizedTypes() { + return true; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java index 3f24c939b2..0a185953ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java @@ -599,4 +599,9 @@ public class PostgreSQL81Dialect extends Dialect { public IdentityColumnSupport getIdentityColumnSupport() { return new PostgreSQL81IdentityColumnSupport(); } + + @Override + public boolean supportsNationalizedTypes() { + return false; + } }