问题描述
假设我有这样的实体:
public class Foo {
private long id;
私人列表< Bar> list = new ArrayList<>();
public long getId(){
return id;
}
public void setId(long id){
this.id = id;
}
公开列表< Bar> getList(){
return list;
public void setList(List< Bar> list){
this.list = list;
}
/ **帮助程序方法* /
public boolean isEmpty(){
return list.isEmpty();
$ / code $ / pre
&相应的实体映射:
<?xml version =1.0encoding =UTF-8?>
< entity-mappings xmlns =http://xmlns.jcp.org/xml/ns/persistence/orm
xmlns:xsi =http://www.w3.org/2001 / XMLSchema-instance
xsi:schemaLocation =http://xmlns.jcp.org/xml/ns/persistence/orm
version =2.1>
< entity class =Foo>
< table name =foo/>
<属性>
< id name =id/>
<一对多名称=列表>
<! - ... - >
< /一对多>
<临时名称=isEmpty/>
< / attributes>
< / entity>
< / entity-mappings>
和这个例外,我得到了: org.hibernate.PropertyNotFoundException:找不到为属性setter方法[富#空]
结果,
我发现了类似的交 - 并有北阳注释帮助。
解决方案 通过指定<暂态名称= 的isEmpty/>
您尝试向JPA提供程序发出信号,表明您有一个名为 isEmpty
的临时属性。您的财产实际上被命名为空
,而不是 isEmpty
,并且错误消息也表明也是( FOO#空
)。将相应的XML标记替换为< transient name =empty/>
。
Suppose I have such entity:
public class Foo {
private long id;
private List<Bar> list = new ArrayList<>();
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public List<Bar> getList() {
return list;
}
public void setList(List<Bar> list) {
this.list = list;
}
/** helper method*/
public boolean isEmpty(){
return list.isEmpty();
}
}
And corresponding entity mapping:
<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm"
version="2.1">
<entity class="Foo">
<table name="foo"/>
<attributes>
<id name="id"/>
<one-to-many name="list">
<!-- ... -->
</one-to-many>
<transient name="isEmpty"/>
</attributes>
</entity>
</entity-mappings>
And this exception I got:org.hibernate.PropertyNotFoundException: Could not locate setter method for property [Foo#empty]
I found a similar post - HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter and there Trainsient annotation on such method helped.
解决方案 By specifying <transient name="isEmpty"/>
you try to signal to the JPA provider that you have a transient property named isEmpty
. Your property is actually named empty
, not isEmpty
, and the error message indicates that too (Foo#empty
). Replace the corresponding XML tag with <transient name="empty"/>
.
这篇关于PropertyNotFoundException:无法找到setter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!