<small id='AWeeO'></small><noframes id='AWeeO'>

<i id='AWeeO'><tr id='AWeeO'><dt id='AWeeO'><q id='AWeeO'><span id='AWeeO'><b id='AWeeO'><form id='AWeeO'><ins id='AWeeO'></ins><ul id='AWeeO'></ul><sub id='AWeeO'></sub></form><legend id='AWeeO'></legend><bdo id='AWeeO'><pre id='AWeeO'><center id='AWeeO'></center></pre></bdo></b><th id='AWeeO'></th></span></q></dt></tr></i><div id='AWeeO'><tfoot id='AWeeO'></tfoot><dl id='AWeeO'><fieldset id='AWeeO'></fieldset></dl></div>

      <legend id='AWeeO'><style id='AWeeO'><dir id='AWeeO'><q id='AWeeO'></q></dir></style></legend>
        <bdo id='AWeeO'></bdo><ul id='AWeeO'></ul>
      1. <tfoot id='AWeeO'></tfoot>

        休眠强制时间戳以保持/加载为 UTC

        时间:2023-07-25
          <tbody id='MGvH3'></tbody>
        <legend id='MGvH3'><style id='MGvH3'><dir id='MGvH3'><q id='MGvH3'></q></dir></style></legend>

        <small id='MGvH3'></small><noframes id='MGvH3'>

          <i id='MGvH3'><tr id='MGvH3'><dt id='MGvH3'><q id='MGvH3'><span id='MGvH3'><b id='MGvH3'><form id='MGvH3'><ins id='MGvH3'></ins><ul id='MGvH3'></ul><sub id='MGvH3'></sub></form><legend id='MGvH3'></legend><bdo id='MGvH3'><pre id='MGvH3'><center id='MGvH3'></center></pre></bdo></b><th id='MGvH3'></th></span></q></dt></tr></i><div id='MGvH3'><tfoot id='MGvH3'></tfoot><dl id='MGvH3'><fieldset id='MGvH3'></fieldset></dl></div>

            <bdo id='MGvH3'></bdo><ul id='MGvH3'></ul>

                • <tfoot id='MGvH3'></tfoot>
                • 本文介绍了休眠强制时间戳以保持/加载为 UTC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 java、mysql、hibernate (3.6.x).在 java 方面,我使用 java.sql.Timestamp 对象.在 mysql 方面,我使用的是日期时间列.

                  I'm using java, mysql, hibernate (3.6.x). On the java side I'm using java.sql.Timestamp objects. On the mysql side I'm using datetime columns.

                  我希望 hibernate 使用 UTC 时区保存/加载这些 Timestamp 对象,而不考虑系统/java/mysql 时区.

                  I want hibernate to save/load these Timestamp objects using UTC time zone regardless of system/java/mysql time zone.

                  我发现如何以 UTC 存储日期/时间和时间戳JPA 和 Hibernate 的时区",它提供了丰富的信息,但缺少一些我正在努力寻找的最终实现信息.

                  I found " How to store date/time and timestamps in UTC time zone with JPA and Hibernate " which was informative but lacking some final implementation info which I'm struggling to find.

                  我想实现一个 UtcTimestampTypeDescriptor,如该线程中所示,并将休眠配置为使用它而不是普通的 TimestampTypeDescriptor.

                  I want to implement a UtcTimestampTypeDescriptor as shown in that thread and configure hibernate to use this instead of the normal TimestampTypeDescriptor.

                  如何将休眠配置为使用 UtcTimestamp 类型而不是默认的 Timestamp 类型?

                  How can I configure hibernate to use the UtcTimestamp type instead of the default Timestamp type?

                  推荐答案

                  仅适用于 MySQL,实现自定义 Hibernate 类型的替代方法是将以下 JDBC 选项添加到 JDBC 连接 URL:p>

                  For MySQL only, an alternative to implementing custom Hibernate types is to add the following JDBC options to your JDBC connection URL:

                  useTimezone=true
                  serverTimezone=UTC
                  

                  这将强制您的 JDBC 连接到 UTC 时区,并要求 MySQL 从 JVM 时区执行转换.最终效果是您可以在 JVM 上保留本地时区(例如,用于打印日志消息等),而 DATETIME 列将保留为 UTC.

                  This will force your JDBC connection into the UTC timezone and ask MySQL to perform conversions from the JVM timezone. The net effect is that you can keep a local timezone on your JVM (e.g. for printing out log messages and so forth), while DATETIME columns will be persisted as UTC.

                  例如:

                  <bean id="hibernateAnalysisSessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
                      <property name="hibernateProperties">
                          <props>
                              <!-- Connection parameters -->
                              <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
                              <prop key="hibernate.connection.url">jdbc:mysql://hostname/databaseName?useTimezone=true&amp;serverTimezone=UTC</prop>
                              ...
                  

                  这篇关于休眠强制时间戳以保持/加载为 UTC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我应该在 Java 8 中使用哪个日期类? 下一篇:Android将中部时间转换为当地时间

                  相关文章

                  最新文章

                    <legend id='cxUGO'><style id='cxUGO'><dir id='cxUGO'><q id='cxUGO'></q></dir></style></legend>
                    <i id='cxUGO'><tr id='cxUGO'><dt id='cxUGO'><q id='cxUGO'><span id='cxUGO'><b id='cxUGO'><form id='cxUGO'><ins id='cxUGO'></ins><ul id='cxUGO'></ul><sub id='cxUGO'></sub></form><legend id='cxUGO'></legend><bdo id='cxUGO'><pre id='cxUGO'><center id='cxUGO'></center></pre></bdo></b><th id='cxUGO'></th></span></q></dt></tr></i><div id='cxUGO'><tfoot id='cxUGO'></tfoot><dl id='cxUGO'><fieldset id='cxUGO'></fieldset></dl></div>
                  1. <tfoot id='cxUGO'></tfoot>

                    <small id='cxUGO'></small><noframes id='cxUGO'>

                      • <bdo id='cxUGO'></bdo><ul id='cxUGO'></ul>