HHH-10693 - Fix PostgreSQL should not use nvarchar when using Nationaliztaion

This commit is contained in:
Andrea Boriero 2016-04-18 11:31:38 +01:00 committed by Gail Badner
parent c1023ac49e
commit 513c2358f7
3 changed files with 28 additions and 2 deletions

View File

@ -39,6 +39,8 @@ import org.hibernate.cfg.Ejb3JoinColumn;
import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.cfg.NotYetImplementedException;
import org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass; import org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass;
import org.hibernate.cfg.SetSimpleValueTypeSecondPass; 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.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.SimpleValue; import org.hibernate.mapping.SimpleValue;
@ -150,8 +152,10 @@ public class SimpleValueBinder {
typeParameters.clear(); typeParameters.clear();
String type = BinderHelper.ANNOTATION_STRING_DEFAULT; String type = BinderHelper.ANNOTATION_STRING_DEFAULT;
if ( getDialect().supportsNationalizedTypes() ) {
isNationalized = property.isAnnotationPresent( Nationalized.class ) isNationalized = property.isAnnotationPresent( Nationalized.class )
|| buildingContext.getBuildingOptions().useNationalizedCharacterData(); || buildingContext.getBuildingOptions().useNationalizedCharacterData();
}
Type annType = null; Type annType = null;
if ( (!key && property.isAnnotationPresent( Type.class )) if ( (!key && property.isAnnotationPresent( Type.class ))
@ -307,6 +311,14 @@ public class SimpleValueBinder {
applyAttributeConverter( property, attributeConverterDescriptor ); applyAttributeConverter( property, attributeConverterDescriptor );
} }
private Dialect getDialect() {
return buildingContext.getBuildingOptions()
.getServiceRegistry()
.getService( JdbcServices.class )
.getJdbcEnvironment()
.getDialect();
}
private void applyAttributeConverter(XProperty property, AttributeConverterDescriptor attributeConverterDescriptor) { private void applyAttributeConverter(XProperty property, AttributeConverterDescriptor attributeConverterDescriptor) {
if ( attributeConverterDescriptor == null ) { if ( attributeConverterDescriptor == null ) {
return; return;

View File

@ -2850,4 +2850,13 @@ public abstract class Dialect implements ConversionContext {
public boolean supportsNamedParameters(DatabaseMetaData databaseMetaData) throws SQLException { public boolean supportsNamedParameters(DatabaseMetaData databaseMetaData) throws SQLException {
return databaseMetaData != null && databaseMetaData.supportsNamedParameters(); return databaseMetaData != null && databaseMetaData.supportsNamedParameters();
} }
/**
* Does this dialect supports Nationalized Types
*
* @return boolean
*/
public boolean supportsNationalizedTypes() {
return true;
}
} }

View File

@ -599,4 +599,9 @@ public class PostgreSQL81Dialect extends Dialect {
public IdentityColumnSupport getIdentityColumnSupport() { public IdentityColumnSupport getIdentityColumnSupport() {
return new PostgreSQL81IdentityColumnSupport(); return new PostgreSQL81IdentityColumnSupport();
} }
@Override
public boolean supportsNationalizedTypes() {
return false;
}
} }