首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PropertyNotFoundException:找不到策划人

PropertyNotFoundException:找不到策划人
EN

Stack Overflow用户
提问于 2016-10-17 20:36:06
回答 1查看 4.7K关注 0票数 0

假设我有这样一个实体:

代码语言:javascript
复制
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();
  }
}

以及相应的实体映射:

代码语言:javascript
复制
 <?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>

我得到的例外是:org.hibernate.PropertyNotFoundException: Could not locate setter method for property [Foo#empty]

我发现了一个类似的后HIbernate Mapping Exception: PropertyNotFoundException: Could not find a setter,在这种方法上的Trainsient注释也有帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-17 20:40:17

通过指定<transient name="isEmpty"/>,您尝试向JPA提供程序发出信号,表示您有一个名为isEmpty的瞬态属性。您的属性实际上名为empty,而不是isEmpty,错误消息也指出了这一点(Foo#empty)。用<transient name="empty"/>替换相应的XML标记。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40095224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档