I've decided to try soft delete mechanism that was described in this article . There is an AbstractEntity in my domain model with deleted indicator:
@MappedSuperclass
abstract class AbstractEntity {
@Column(name = "deleted_ind", nullable = false)
Boolean deleted = Boolean.FALSE
}
And there is a Job entity:
@Entity
@Table(name = "job")
@SQLDelete(sql = "UPDATE job SET deleted_ind = true WHERE job_id = ?")
@Loader(namedQuery = "findJobById")
@NamedQuery(name = "findJobById", query =
"SELECT j FROM Job j WHERE j.id = ? AND j.deleted = false")
@Where(clause = "deleted_ind = false")
class Job extends AbstractEntity {
@Id
@Column(name = "job_id", nullable = false)
String id
}
But when i'm trying to run my integration tests using h2 in-memory, exception occurs:
Hibernate: UPDATE job SET deleted_ind = true WHERE job_id = ?
2017-03-13 10:24:13,719 [main] INFO o.h.e.j.b.i.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
2017-03-13 10:24:13,720 [main] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 90008, SQLState: 90008
2017-03-13 10:24:13,720 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Invalid value "2" for parameter "parameterIndex" [90008-192]
Caused by: org.hibernate.exception.GenericJDBCException: could not delete: [com.tolledo.myapp.Job#a]
Caused by: org.h2.jdbc.JdbcSQLException: Invalid value "2" for parameter "parameterIndex" [90008-192]
Could you please assist with this issue?
UPDATE: Simple Spring data JpaRepository is being used and in this particular test 'detete' method is being called.
FINAL UPDATE: Oh, i just realized that i forgot to add 'version' to query. There is
@Version
@Column(name = "version", nullable = false)
Integer version
in my AbstractEntity, so final SQLDELETE looks like:
@SQLDelete(sql = "UPDATE job SET deleted_ind = true WHERE job_id = ? and version = ?")
Change SQL this way
@SQLDelete(sql = "UPDATE job SET deleted_ind = 1 WHERE job_id = ?")
@Where(clause = "deleted_ind = 0")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.