threeten-jpa
threeten-jpa copied to clipboard
org.hibernate.MappingException: No Dialect mapping for JDBC type: 2014 when using Jdbc42OffsetDateTimeType
Hi I am using the latest version of spring boot (1.5.3) and I'm trying to map a OffsetDateTime to a Postgres timestamp with timezone using latest JDBC driver (4.2). My mapping is as follows:
@Column @Type(type = Jdbc42OffsetDateTimeType.NAME) private OffsetDateTime recommendedAt;
This is the error I get:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2014 at org.hibernate.dialect.TypeNames.get(TypeNames.java:70) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
Is there anything specific I still need to do or is this just not working?
I fear the UserTypes are not compatible with Hibernate 5.0. The UserType interface was changed from 5.0 to 5.2, most notably the argument type changed from SessionImplementor to SharedSessionContractImplementor. Likely you have more exceptions on the log due to this.
Spring Boot defaults to Hibernate 5.0.12 but supports Hibernate 5.2. My recommendation would be to upgrade to Hibernate 5.2 it that is an option for you.
I just upgraded to Hibernate 5.2 and get exactly the same error:
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: 2014 at org.hibernate.dialect.TypeNames.get(TypeNames.java:70) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.dialect.TypeNames.get(TypeNames.java:101) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:342) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.mapping.Column.getSqlType(Column.java:231) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.StandardTableExporter.getSqlCreateStrings(StandardTableExporter.java:96) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.StandardTableExporter.getSqlCreateStrings(StandardTableExporter.java:30) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:346) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(SchemaMigratorImpl.java:256) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:136) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:109) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:65) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:307) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:490) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:878) ~[hibernate-core-5.2.2.Final.jar:5.2.2.Final] ... 121 common frames omitted
Do you actually have an working example that this works with latest spring boot version (aka 1.5.3) and Hibernate 5.2?
I do not have a working example with Spring Boot. The only working example I have is with "vanilla" Spring ORM and persistence.xml where I explicitly set the hibernate dialect. Your exception seems to happen during DDL generation.
This is not an issue with the UserTypes in this project or Spring Boot support but with Hibernate not supporting TIMESTAMP WITH TIME ZONE for schema generation. If you have a look at the Dialect constructor TIMESTAMP_WITH_TIMEZONE (2014) is not registered.
I'll see if I can report an issue against Hibernate.
A quick work around would be to use
@Column(columnDefinition = "TIMESTAMP WITH TIME ZONE")
@Type(type = Jdbc42OffsetDateTimeType.NAME)
private OffsetDateTime recommendedAt;
Bug and PR https://hibernate.atlassian.net/browse/HHH-11773 https://github.com/hibernate/hibernate-orm/pull/1916
I see so the DDL generation is the issue. Thanks a lot for looking into it and making the PR, hopefully it get merged soon! I will try the workaround till then. Will try again the DDL setup once the PR gets merged.
How many columns are we talking about? If it's several columns you could also create your own dialect like this
public class PatchedPostgreSQL95Dialect extends PostgreSQL95Dialect {
public PatchedPostgreSQL95Dialect() {
super();
registerColumnType(Types.TIME_WITH_TIMEZONE, "time with time zone");
registerColumnType(Types.TIMESTAMP_WITH_TIMEZONE, "timestamp with time zone");
}
}
this would also take care of things.
Thanks I do have a lot of fields so I will rather use the patched dialect (seems to work fine). Hopefully the patch gets merged soon.