Home:ALL Converter>why SQL Server timestamp type is mapped to Binary type in hibernate?

why SQL Server timestamp type is mapped to Binary type in hibernate?

Ask Time:2015-07-13T15:31:31         Author:Sunil Kumar

Json Formatter

I have a table with a column type as TimeStamp in Mssql and generated pojos using hibernate(reverse engineering).In the generated Pojo,timestamp field is marked as byte[].

In the debugging process,I found TimeStamp sqlType code is "-2" that is Binary Type in Hibernate types and Hibernate binary type is equivalent to byte[] in java.

Java, hibernate and sql server for timestamp data type

 Mssql                 Hibernate             Java Type
 -----                 ---------             ---------

Timestamp               Binary                 byte[]

I dont understand why only mssql type TimeStamp is mapped with Binary in Hibernate.But in other databases like Postgres,oracle,mysql...timestamp is mapped to hibernate timestamp type.

I can resolve this issue by adding type-mapping in hibernate.reveng.xml by mapping sql timestamp to hibernate timestamp. Dont know what else issues occurs further.

Author:Sunil Kumar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31377666/why-sql-server-timestamp-type-is-mapped-to-binary-type-in-hibernate
Sunil Kumar :

It seems MSSQL Timestamp is different from all other databases Timestamp type.\n\nSQL Server timestamps are binary numbers that indicate the relative sequence in which data modifications took place in a database. The timestamp data type was originally implemented to support the SQL Server recovery algorithms.\n\nSQL Server TIMESTAMP value does not contain any date or time related value. It is not dependent on system date. In fact, it contains binary format string to denote a version of a row in table. That is why it is also called ROWVERSION. Also, ROWVERSION is the keyword in SQL Server which has the same behavior as TIMESTAMP.\n\nHence Hibernate is mapping sql server timestamp type to Binary type.",
2015-07-13T09:18:42
yy