如何在@SQLDelete中处理多个参数?

时间:2013-10-15 09:38:51

标签: java hibernate hibernate-annotations

我将@SQLDelete注释定义为 -

@SQLDelete(sql = "UPDATE item SET deleted = 1  WHERE id = ? and version=? ")

当我在item上调用删除时,我无法通过version而我收到以下异常 -

org.springframework.dao.InvalidDataAccessResourceUsageException: could not delete:
com.hk.domain.order.Item#30000004]; SQL [UPDATE item SET deleted = 1  WHERE id = ? and
version=? ]; nested exception is org.hibernate.exception.SQLGrammarException: could not
delete: [com.hk.domain.order.Item#30000004]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:629)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
.
.
.
.
Caused by: java.sql.SQLException: No value specified for parameter 2
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2513)
at com.mysql.jdbc.PreparedStatement.addBatch(PreparedStatement.java:1007)
at org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:175)
at org.apache.commons.dbcp.DelegatingPreparedStatement.addBatch(DelegatingPreparedStatement.java:175)
at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:53)
at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2548)
... 93 more

我认为该版本应该从item对象本身获取,但这种情况不会发生。

无论如何都要通过该版本?当有多个参数时,如何使用此注释?我到处寻找,但对于有2个参数的情况无法得到任何解决方案。

提前致谢。

0 个答案:

没有答案