如何在Hibernate中存储LocalTime [英] How to store LocalTime in hibernate

查看:153
本文介绍了如何在Hibernate中存储LocalTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个实体有一个 LocalTime 类型的变量,我想将它存储在数据库中。所以我有两个问题:


  1. mysql中的字段是什么数据类型?

  2. 什么注解用于实体?

我不关心日期。

解决方案

hibernate-java8 为持久化 LocalTime 字段提供了一个LocalTimeType。由于hibernate-java8-5.2。+已被合并到hibernate-core模块中。

用法



保存 LocalTime as sql time柱。

  @Column 
私有LocalTime时间;

保存 LocalTime as sql varchar column。

  @Column(columnDefinition =varchar(8))
私有LocalTime时间;


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.

解决方案

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;

这篇关于如何在Hibernate中存储LocalTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆