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

前端 未结 7 918
天涯浪人
天涯浪人 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:46

    There are some classes in the Java platform libraries that do extend an instantiable class and add a value component. For example, java.sql.Timestamp extends java.util.Date and adds a nanoseconds field. The equals implementation for Timestamp does violate symmetry and can cause erratic behavior if Timestamp and Date objects are used in the same collection or are otherwise intermixed. The Timestamp class has a disclaimer cautioning programmers against mixing dates and timestamps. While you won’t get into trouble as long as you keep them separate, there’s nothing to prevent you from mixing them, and the resulting errors can be hard to debug. This behavior of the Timestamp class was a mistake and should not be emulated.

    check out this link

    http://blogs.sourceallies.com/2012/02/hibernate-date-vs-timestamp/

提交回复
热议问题