Hibernate Criteria - 时间戳查询始终评估为0000-00-00 00:00:00

时间:2016-01-28 14:49:24

标签: java mysql hibernate datetime timestamp

我正在使用Hibernate Criteria进行查询,以便在某个时间戳之后获取所有用户,由于某些原因我总是收到此错误(Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp),但这是不正确的,因为这是标准(CriteriaImpl(com.tradeit.services.data.model.User:this[][updatedAt>2016-01-01 00:00:00.0]) )你可以看到时间戳是2016-01-01 00:00:00而不是00:00:00。

用户updatedAt字段的类型为java.sql.Timestamp:

class User {
  ...
  private Timestamp updatedAt;
  ...
  public Timestamp getUpdatedAt() {
    return updatedAt;
  }

  public void setUpdatedAt(Timestamp updatedAt) {
    this.updatedAt = updatedAt;
  }
}

<hibernate-mapping>
  <class name="com.tradeit.services.data.model.User" table="User">
    ...
    <property name="updatedAt" type="java.sql.Timestamp" />
    ...
  </class>
</hibernate-mapping>    

这是日志输出:

16:03:09,538 INFO  [TILogger] (default task-10) Getting list for criteria: CriteriaImpl(com.tradeit.services.data.model.User:this[][updatedAt>2016-01-01 00:00:00.0])
16:03:09,539 INFO  [stdout] (default task-10) Hibernate: select this_.id as id1_10_0_, this_.firstName as firstNam2_10_0_, this_.lastName as lastName3_10_0_, this_.password as password4_10_0_, this_.tempPassword as tempPass5_10_0_, this_.email as email6_10_0_, this_.telephone as telephon7_10_0_, this_.countryId as countryI8_10_0_, this_.channels as channels9_10_0_, this_.isRegistered as isRegis10_10_0_, this_.isAdmin as isAdmin11_10_0_, this_.isOnTrial as isOnTri12_10_0_, this_.tempPasswordRequestTime as tempPas13_10_0_, this_.lastPayment as lastPay14_10_0_, this_.updatedAt as updated15_10_0_, this_.createdAt as created16_10_0_ from User this_ where this_.updatedAt>?

16:03:09,545 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-10) SQL Error: 0, SQLState: S1009
16:03:09,545 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-10) Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
16:03:09,546 ERROR [io.undertow.request] (default task-10) UT005023: Exception handling request to /services/rest/Users/query: org.jboss.resteasy.spi.UnhandledException: org.hibernate.exception.GenericJDBCException: could not execute query

奇怪的是,我有其他类也有一个updatedAt时间戳和相同的确切查询工作但由于某种原因只有User类时间戳以某种方式失去其值并成为00:00:00: 00。

我已经完成了所有尝试,找到了User类,表和映射与其他类,表和映射之间不同的东西,它们都是相同的类型,具有相同的精确映射和所有内容。

0 个答案:

没有答案