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