Carlos Garces
Carlos Garces

Reputation: 833

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

Upvotes: 3

Views: 1099

Answers (1)

Carlos Garces
Carlos Garces

Reputation: 833

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

Upvotes: 6

Related Questions