我正在尝试修改一个实体,该实体具有一对多关系映射到它的对象列表,但是由于以下错误它总是失败。
[请求处理失败;嵌套异常为 org.springframework.beans.InvalidPropertyException:无效的属性 Bean类的“ storeClosureCashSet [0]” [application.model.StoreClosure]:属性的获取程序 'storeClosureCashSet'引发异常;嵌套异常为 根本原因的java.lang.reflect.InvocationTargetException]
java.lang.NullPointerException:空
我一直在尝试其他几种选择,但这根本行不通。我无法更改列表,我需要将其保留为集合。
当我加载页面时,输入设置正确,并且一切都按原样显示,但是在提交表单时总是会发生错误。您可以在下面查看我的代码。
所以我在Thymeleaf中得到了以下形式。
<form form id="closure-form" th:object="${closure}" th:action="@{/url}" method="post">
<input hidden="hidden" th:field=*{id}/>
<!-- Some other fields -->
<div class="full-width align-center no-margins">
<th:block th:each="item, cashStat : *{storeClosureCashSet}">
<div class="half-width no-margins align-center">
<input hidden="hidden" class="hidden" th:field="*{storeClosureCashSet[__${cashStat.index}__].storeClosureCashPK}"/>
<input hidden="hidden" class="hidden" th:field="*{storeClosureCashSet[__${cashStat.index}__].storeClosureFK}"/>
<input hidden="hidden" class="hidden" th:field="*{storeClosureCashSet[__${cashStat.index}__].exchangeRate}"/>
<input hidden="hidden" class="hidden" th:field="*{storeClosureCashSet[__${cashStat.index}__].currency}"/>
<input class="minimalist-input minimalist-number-input minimalist-number-format align-center currency-crc" th:field="*{storeClosureCashSet[__${cashStat.index}__].amount}"/>
</div>
</th:block>
</div>
</form>
这是实体的代码。
public class StoreClosure {
private Long id;
// Some other fields.
// Getters and setters of some other fields.
private Set<StoreClosureCash> storeClosureCashSet;
public Set<StoreClosureCash> getStoreClosureCashSet() {
return new HashSet<StoreClosureCash>(this.storeClosureCashSet);
}
}
我的Hibernate配置。
<hibernate-mapping>
<class name="application.model.StoreClosure" table="STORE_CLOSURE" schema="dbo" catalog="DB">
<id name="storeClosurePK">
<column name="id" sql-type="bigint"/>
<generator class="identity"/>
</id>
<!-- Some other fields -->
<set name="storeClosureCashSet" inverse="true" lazy="true" fetch="join">
<key>
<column name="store_closure_fk" sql-type="long" not-null="true"/>
</key>
<one-to-many class="application.model.StoreClosureCash"/>
</set>
</hibernate-mapping>
这就是我的控制器代码。
@PostMapping(value = "/url")
public String updateStoreClosure(@ModelAttribute StoreClosure storeClosure) {
// Some code.
return "page";
}
我真的需要了解发生了什么。非常感谢您的帮助。