We're updating the issue view to help you get more done. 

PostgreSQL should not use nvarchar when using Nationalization

Description

When running the org.hibernate.userguide.mapping.basic.NationalizedTest using PostgreSQL, we get the following exception:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [ create table Product ( id int4 not null, name varchar(255), warranty nvarchar(255), primary key (id) )] at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlString(SchemaCreatorImpl.java:434) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.applySqlStrings(SchemaCreatorImpl.java:419) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.createFromMetadata(SchemaCreatorImpl.java:310) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.performCreation(SchemaCreatorImpl.java:165) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:134) at org.hibernate.tool.schema.internal.SchemaCreatorImpl.doCreation(SchemaCreatorImpl.java:120) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:148) at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:458) at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:881) at org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase.buildEntityManagerFactory(BaseEntityManagerFunctionalTestCase.java:79) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:74) Caused by: org.postgresql.util.PSQLException: ERROR: type "nvarchar" does not exist

Second, the PostgreSQL driver does not support Statement.setNVarChar either, and so we cannot use the NVarcharTypeDescriptor for PostgreSQL.

1 2 3 4 Caused by: java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc4.Jdbc4PreparedStatement.setNString(int, String) is not yet implemented. at org.postgresql.Driver.notImplemented(Driver.java:670) at org.postgresql.jdbc4.AbstractJdbc4Statement.setNString(AbstractJdbc4Statement.java:101) at org.hibernate.type.descriptor.sql.NVarcharTypeDescriptor$1.doBind(NVarcharTypeDescriptor.java:46)

Accodring to this site and this SO question, The PostgreSQL VARCHAR plays the role of an NVARCHAR in other DBs,

Environment

None

Status

Assignee

Andrea Boriero

Reporter

Vlad Mihalcea

Components

Fix versions

Affects versions

5.1.0
5.0.9

Priority

Major