3

I'm trying to make use of the Java 8 date & time API in a new application which is backed by SQL Server database. All the resources on the Internet state that Hibernate 5.2+ support this API and Java 8 out of the box and suggest a simple approach as:

@Entity
@Table(name="...", schema="...")
public class DepositDetails {

    // ... id, other fields ...

    private LocalDateTime createdOn;

    // ... other fields, getters/setters ...

}

In my case, however, the column which is created in the database (using hibernate-jpamodelgen), is created as VARBINARY(255) instead of DATETIME/DATETIME2.
I've also tried specifying the datatype explicitly (columnDefinition = "DATETIME") - in this case the column type is created correctly as specified, but when I try to persist data in the table, I get an exception stating that varbinary data cannot be converted to datetime...

Some more details about the application setup that may be related to the issue:

  • Hibernate is 5.2.12.Final
  • SQL Server is Microsoft SQL Server Developer Edition (64-bit) 14.0.900.75 (in a Docker container)
  • MSSQL JDBC driver is 6.2.2.jre8
Giovanni
  • 332
  • 3
  • 12
  • Validate that it is actually 5.2+ on the runetime classpath as this should work. http://in.relation.to/2016/06/01/hibernate-orm-520-final-release/ – Alan Hay Oct 28 '17 at 09:07

1 Answers1

0

The problem was, as suggested by @Alan Hay, that Hibernate 5.2 was replaced in the dependency tree by Hibernate 5.0, which is used by default by Spring Boot.
Moreover, I had a property in my child pom.xml which was set to 5.2.12.Final, but on a parent level the same property was set (again by Spring Boot) to 5.0.x. In this way the parent application, which should have taken the 5.2 dependency from the child module, was actually taking the old version from Spring Boot.
The solution was to set the property in the parent pom.xml.

Giovanni
  • 332
  • 3
  • 12