How to use the Java 8 LocalDateTime with JPA and Hibernate

后端 未结 5 1194
鱼传尺愫
鱼传尺愫 2020-11-27 18:22

I have the following class description snippet:

... 
@Column(name = \"invalidate_token_date\")
@Temporal(TemporalType.TIMESTAMP)
private LocalDateTime inv         


        
5条回答
  •  醉话见心
    2020-11-27 19:21

    For any Hibernate 5.x users, there is

    
        org.hibernate
        hibernate-java8
        5.0.0.Final
    
    

    You don't need to do anything else. Just add the dependency, and the Java 8 time types should work like any other basic types, no annotations required.

    private LocalDateTime invalidateTokenDate;
    

    Note: this won't save to timestamp type though. Testing with MySQL, it saves to datetime type.

提交回复
热议问题