• <tfoot id='sizpC'></tfoot>

    1. <legend id='sizpC'><style id='sizpC'><dir id='sizpC'><q id='sizpC'></q></dir></style></legend>

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

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

        • <bdo id='sizpC'></bdo><ul id='sizpC'></ul>
      1. 设置由数据库生成的 JPA 时间戳列?

        时间:2023-07-27
        • <bdo id='DY3UY'></bdo><ul id='DY3UY'></ul>

          <legend id='DY3UY'><style id='DY3UY'><dir id='DY3UY'><q id='DY3UY'></q></dir></style></legend>

            <i id='DY3UY'><tr id='DY3UY'><dt id='DY3UY'><q id='DY3UY'><span id='DY3UY'><b id='DY3UY'><form id='DY3UY'><ins id='DY3UY'></ins><ul id='DY3UY'></ul><sub id='DY3UY'></sub></form><legend id='DY3UY'></legend><bdo id='DY3UY'><pre id='DY3UY'><center id='DY3UY'></center></pre></bdo></b><th id='DY3UY'></th></span></q></dt></tr></i><div id='DY3UY'><tfoot id='DY3UY'></tfoot><dl id='DY3UY'><fieldset id='DY3UY'></fieldset></dl></div>
          1. <tfoot id='DY3UY'></tfoot>
          2. <small id='DY3UY'></small><noframes id='DY3UY'>

                <tbody id='DY3UY'></tbody>
                • 本文介绍了设置由数据库生成的 JPA 时间戳列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在我的 SQL Server 2000 数据库中,我有一个名为 lastTouched 的类型为 DATETIME 的时间戳(在函数中,不在数据类型中)列设置为 getdate() 作为其默认值/绑定.

                  In my SQL Server 2000 database, I have a timestamp (in function not in data type) column of type DATETIME named lastTouched set to getdate() as its default value/binding.

                  我正在使用 Netbeans 6.5 生成的 JPA 实体类,并在我的代码中有这个

                  I am using the Netbeans 6.5 generated JPA entity classes, and have this in my code

                  @Basic(optional = false)
                  @Column(name = "LastTouched")
                  @Temporal(TemporalType.TIMESTAMP)
                  private Date lastTouched;
                  

                  但是,当我尝试将对象放入我得到的数据库时,

                  However when I try to put the object into the database I get,

                  javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.generic.Stuff.lastTouched
                  

                  我尝试将 @Basic 设置为 (optional = true),但这会引发异常,提示数据库不允许 nullTIMESTAMP 列的 code> 值,并非设计使然.

                  I've tried setting the @Basic to (optional = true), but that throws an exception saying the database doesn't allow null values for the TIMESTAMP column, which it doesn't by design.

                  ERROR JDBCExceptionReporter - Cannot insert the value NULL into column 'LastTouched', table 'DatabaseName.dbo.Stuff'; column does not allow nulls. INSERT fails.
                  

                  我以前让它在纯 Hibernate 中工作,但后来我切换到 JPA 并且不知道如何告诉它该列应该在数据库端生成.请注意,我仍然使用 Hibernate 作为我的 JPA 持久层.

                  I previously got this to work in pure Hibernate, but I have since switched over to JPA and have no idea how to tell it that this column is supposed to be generated on the database side. Note that I am still using Hibernate as my JPA persistence layer.

                  推荐答案

                  我通过将代码更改为解决了这个问题

                  I fixed the issue by changing the code to

                  @Basic(optional = false)
                  @Column(name = "LastTouched", insertable = false, updatable = false)
                  @Temporal(TemporalType.TIMESTAMP)
                  private Date lastTouched;
                  

                  因此在生成 SQL 插入时会忽略时间戳列.不确定这是否是解决此问题的最佳方法.欢迎反馈.

                  So the timestamp column is ignored when generating SQL inserts. Not sure if this is the best way to go about this. Feedback is welcome.

                  这篇关于设置由数据库生成的 JPA 时间戳列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Java 中格式化时间戳 下一篇:如何从 java.sql.Timestamp 转换为 java.util.Date?

                  相关文章

                  最新文章

                  <tfoot id='eW8jK'></tfoot>

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

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

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