【问题标题】:Error using hibernate anotations for soft delete使用休眠注释进行软删除时出错
【发布时间】:2013-01-21 15:46:25
【问题描述】:

我有以下 JPA 实体

@SQLDelete(sql="UPDATE service SET date_deletion =  CURRENT_DATE() WHERE id = ?")
@Where(clause="date_deletion IS NULL ")
public class Service {
...
}

选择工作正常,所有通知 date_deletion 的元素都没有显示,但是当我尝试删除时......

16:38:26,836  DEBUG SQL:111 - UPDATE service SET date_deletion =  CURRENT_DATE() WHERE id = ?
16:38:26,836  DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
16:38:26,836  DEBUG JDBCExceptionReporter:225 - could not delete: [com.foo.domain.Service#1] [UPDATE service SET date_deletion =  CURRENT_DATE() WHERE id = ?]
java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).

SQL 出了什么问题?看起来尝试将 CURRENT_DATE() 作为参数处理并期望 2 个参数而不是 1...

【问题讨论】:

    标签: hibernate spring-roo hibernate-annotations


    【解决方案1】:

    已修复。 我正在使用内部处理作为参数发送的“版本”字段的 Spring Roo,正确的注释是:

    @SQLDelete(sql="UPDATE service SET date_deletion=CURRENT_DATE WHERE id=? and version=? ")
    @Where(clause="date_deletion IS NULL ")
    public class Service {
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 2017-12-13
      • 2015-04-05
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 2014-03-17
      相关资源
      最近更新 更多