rvit34 rvit34 - 6 months ago 54
Java Question

PropertyNotFoundException: Could not find a setter

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"

<entity class="Foo">
<table name="foo"/>
<id name="id"/>
<one-to-many name="list">
<!-- ... -->
<transient name="isEmpty"/>


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"/>.