How to store LocalTime in hibernate

一个人想着一个人 提交于 2019-12-22 05:03:04

问题


I have an entity that has a variable of type LocalTime and I would like to store it in database. So I have two questions:

  1. What data type will the field in mysql be?
  2. What annotation to use for entity?

I do not care for date at all whatsoever.


回答1:


hibernate-java8 provide a LocalTimeType for persist a LocalTime field.Since hibernate-java8-5.2.+ has been merged into the hibernate-core module.

Usage

saving LocalTime as sql time column.

@Column
private LocalTime time;

saving LocalTime as sql varchar column.

@Column(columnDefinition = "varchar(8)")
private LocalTime time;


来源:https://stackoverflow.com/questions/43420970/how-to-store-localtime-in-hibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!