How to force Hibernate to return dates as java.util.Date instead of Timestamp?

前端 未结 7 831
天涯浪人
天涯浪人 2020-12-04 08:13

Situation:

I have a persistable class with variable of java.util.Date type:

import java.util.Date;

@Entity
@Table(name = \"prd_peri         


        
7条回答
  •  有刺的猬
    2020-12-04 08:38

    I ran into a problem with this as well as my JUnit assertEquals were failing comparing Dates to Hibernate emitted 'java.util.Date' types (which as described in the question are really Timestamps). It turns out that by changing the mapping to 'date' rather than 'java.util.Date' Hibernate generates java.util.Date members. I am using an XML mapping file with Hibernate version 4.1.12.

    This version emits 'java.util.Timestamp':

    
    

    This version emits 'java.util.Date':

    
    

    Note, however, if Hibernate is used to generate the DDL, then these will generate different SQL types (Date for 'date' and Timestamp for 'java.util.Date').

提交回复
热议问题