How do I binding JPAContainer to TreeTable

Hi Everybody,

I am trying to bind a JPAContainer to a TreeTable. But I have trouble realizing it. Maybe someone can help me out.

I have a Person entity and a Department entity. Whereas a person belongs to a department and a department can have many or non persons. Like in the addressbook example for JPAContainer

When I use a JPAContainer<Person.class>…

JPAContainer<Person> persons = JPAContainerFactory.make(Person.class, Globals.getPersistenceUnitName());
persons.addNestedContainerProperty("department.name");
persons.setParentProperty("department.parent");
        
TreeTable treeTable = new TreeTable();
treeTable.setContainerDataSource(persons);
treeTable.setColumnReorderingAllowed(true);

… I get a NullPointerException:

Mrz 24, 2014 9:15:20 PM com.vaadin.server.DefaultErrorHandler doDefault
Schwerwiegend:
java.lang.NullPointerException
    at com.vaadin.addon.jpacontainer.JPAContainer.getParent(JPAContainer.java:1415)
    at com.vaadin.addon.jpacontainer.JPAContainer.isRoot(JPAContainer.java:1433)
    at com.vaadin.ui.TreeTable$AbstractStrategy.getDepth(TreeTable.java:102)
    at com.vaadin.ui.TreeTable.paintRowAttributes(TreeTable.java:390)
    at com.vaadin.ui.Table.paintRowAttributes(Table.java:3907)
    at com.vaadin.ui.Table.paintRow(Table.java:3794)
    at com.vaadin.ui.Table.paintRows(Table.java:3638)
    at com.vaadin.ui.Table.doPaintContent(Table.java:3226)
    at com.vaadin.ui.Table.paintContent(Table.java:3195)
    at com.vaadin.ui.TreeTable.paintContent(TreeTable.java:496)
    at com.vaadin.server.LegacyPaint.paint(LegacyPaint.java:65)
    at com.vaadin.server.communication.LegacyUidlWrite
.....
...
..

Whereas when I use a JPAContainer<Department.class>…

        JPAContainer<Department> departments = JPAContainerFactory.make(Department.class, Globals.getPersistenceUnitName());
        departments.addNestedContainerProperty("persons.name");
        departments.setParentProperty("parent");
        
        TreeTable treeTable = new TreeTable();
        treeTable.setContainerDataSource(departments);
        treeTable.setColumnReorderingAllowed(true);

… I get a

java.lang.IllegalArgumentException: Invalid property name

How do I do it the proper way? I want to display the departments (hierarchically) and the people working in it. Any help is appreciated.

Thanks in advance.

My Person entity:

@Entity
public class Person implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    
    private String name;
    
    @ManyToOne
    private Department department;
    
    public Person() {
    }


... getter and setters

My Department entity:

@Entity
public class Department implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    private String name;

    @OneToMany(mappedBy = "department")
    private Set<Person> persons;

    @Transient
    private Boolean superDepartment;

    @ManyToOne
    private Department parent;
    
    @Transient
    private String hierarchicalName;

    public Department() {
    }

    .... getter and setters

    public boolean isSuperDepartment() {
        if (superDepartment == null) {
            superDepartment = getPersons().isEmpty();
        }
        return superDepartment;
    }

    public String getHierarchicalName() {
        if (parent != null) {
            return parent.toString() + " : " + name;
        }
        return name;
    }

    @Override
    public String toString() {
        return getHierarchicalName();
    } 

Hi,

Did you find a solution for this problem?

Hello,

I wish he answered you as i’m curiously sitting with the exact same situation at the moment