Hibernate softdelete - 软删除时列索引超出范围异常

时间:2014-03-18 10:52:41

标签: java hibernate exception

我在软删除时遇到以下异常。我不确定错误在哪里?谁可以帮我这个事。提前致谢

    org.springframework.dao.DataIntegrityViolationException: could not delete: [com.ItemResponse#47379632]; SQL [UPDATE fs_item_response SET deleted = '1' WHERE itemresponseid = ?]; nested exception is org.hibernate.exception.DataException: could not delete: [com.ItemResponse#47379632]        
    Caused by: org.postgresql.util.PSQLException: The column index is out of range: 2, number of columns: 1.
    at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:53)
    at org.postgresql.core.v3.SimpleParameterList.setLiteralParameter(SimpleParameterList.java:114)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.bindLiteral(AbstractJdbc2Statement.java:2176)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.setInt(AbstractJdbc2Statement.java:1214)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.setInt(NewProxyPreparedStatement.java:677)
    at org.hibernate.type.IntegerType.set(IntegerType.java:64)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
    at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
    at org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2521)
    ... 80 more
    <hibernate-mapping>
    <class name="com.DataResponse" dynamic-insert="true"
        dynamic-update="true" table="response" where="deleted != 1">
    <id name="id" column="dataresponseid" type="long"
            unsaved-value="-1">
            <generator class="seqhilo">
                <param name="max_lo">1</param>
                <param name="sequence">dataresponse_seq</param>
            </generator>
        </id>           
        <version name="version" column="version"
            type="java.lang.Integer" unsaved-value="null" />            
        <property name="deleted" type="long"  >
            <column name="deleted" default="0"/>
        </property>
        <property name="textResponse" type="java.lang.String"
            update="true" insert="true" column="textresponse" />
        <many-to-one name="dataDetail" class="com.DataDetail" cascade="none" update="true" insert="true" foreign-key="fk_datadetail_datadetailid" column="datadetailid" not-null="true" />
                <sql-delete>UPDATE response SET deleted = '1' WHERE dataresponseid = ?</sql-delete>
    </class>
    </hibernate-mapping>

3 个答案:

答案 0 :(得分:4)

在内部,当在版本化实体上发出删除请求时,似乎Hibernate也将版本号作为第二个参数传递。因此,您需要修改SQLDelete语句以接受version参数。

实施例

UPDATE response SET deleted = '1' WHERE itemresponseid = ? AND version = ?

答案 1 :(得分:0)

deleted的数据类型为long。因此,请从''

中删除SET deleted = '1'

答案 2 :(得分:0)

上述问题通过以下方式解决:

UPDATE响应SET deleted = 1 WHERE itemresponseid =?和-1!=?

@Yohan Liyanage,谢谢你的线索。