Java ZonedDateTime保存在数据库中 [英] Java ZonedDateTime save in the Database

查看:390
本文介绍了Java ZonedDateTime保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模型对象,我想要一个带日期的字段。目前我正在使用 ZonedDateTime ,因为它符合我们的需求。

I have a model object where I want to have a field with a date. For now I am using ZonedDateTime as it fits our needs.

Hibernate将此字段存储在数据库中作为 TINYBLOB 。我们可以将它在数据库中保存的方式更改为更易读的格式,更重要的是更改为可排序格式吗?

Hibernate stores this field in the database as a tinyblob. Can we change the way it is saved in the database to a more readable format and more importantly to a sortable format?

使用的数据库是一个mysql数据库。

The database used is a mysql db.

推荐答案

此问题已作为新的改进 Hibernate 5.0.0.Beta1 ,最初是捆绑在一个孤立的 module hibernate-java8

This issue has already been resolved as a new improvement to Hibernate 5.0.0.Beta1, originally it was bundled in an isolated module hibernate-java8

现在它直接捆绑在 hibernate-core 中,所以请确保你使用的是最新版本的(5.2.X +),如果你使用 maven ,它应该是这样的

Now it is directly bundled in hibernate-core, so just make sure that you are using the recent version of it (5.2.X +), in case you are using maven, it should be like this

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.2.10.Final</version>
</dependency>

这篇关于Java ZonedDateTime保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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