繁体   English   中英

PropertyNotFoundException:找不到设置器

[英]PropertyNotFoundException: Could not find a setter

假设我有这样的实体:

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();
  }
}

以及对应的实体映射:

 <?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映射异常:PropertyNotFoundException:找不到设置器,并且该方法的Trainsient注释有所帮助。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM