gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 06:19:58 28 4
gpt4 key购买 nike

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

    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>

最佳答案

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

例如

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

关于java - Hibernate softdelete - 软删除时列索引超出范围异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22477167/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com