jfan wrote:
I am using Hibernate 3.0.4 with Mssql database. I am using hbm2java to generate my class files, and also using schema export util come with hibernate to generate sql script to create database tables. My mapping file defines a field as date or timestamp type. The generated class file with this field as java.util.Date type, and database type is datatime. Even through I see hours, minutes and seconds has been correctly write to database. When I try to retrieve the object back, the time only has day in it. Does anyone know how to retrieve the time field up to seconds.
Thanks!
MSSQL does not have separate types for Date and Time. To handle that you should use java.sql.Date to persist Date data and java.sql.Time to persist Time only or java.util.Date to pestist date and time. Either way you will have this types persisted in MS SQL as datetime type. It means you will have date and time parts pestisted. Your code responsibility how to treat each one of them. For example if you need to persist time only use in mappings(POJO) java.sql.Time and use in your java code as a time attribute. Then you should be fine.