Search code examples
hibernatespring-roohibernate-annotations

Error using hibernate anotations for soft delete


I have the following JPA entity

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

Select work ok all the elements with date_deletion informed not are show, but when I try to delete....

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).

What is wrong in the SQL? looks like try to handle CURRENT_DATE() as parameter and expect 2 parameters instead of 1...


Solution

  • Fixed. I'm using Spring Roo that internally handle a "version" field that is send as parameter, the correct anotation is:

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