Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
JPA getResultList + BeanItemContainer + Table incompatible?
I'm attempting to attach the List from a JPA getResultList() call to a table via a BeanItemContainer. Essentially, the code looks like this:
List<Therapist> resultList = therapistQuery.getResultList(); therapistTable.setSelectable(true); therapistTable.setMultiSelect(false); therapistTable.setImmediate(true); therapistTable.setContainerDataSource(new BeanItemContainer(resultList));
The behaviour I'm seeing is: only one row of the resultList is shown in the table (and I have confirmed that there is more than one item in the resultList), and that the valueChange() method is not triggered when you select the row in the table.
The classes returned by the query (there are 3 tables involved, in a grandparent, parent, child relationship joined by a single foreign key column each) are full of JPA annotations (i.e. @NamedQuery, @Entity, @Column, @ManyToOne, @JoinColumn, etc.) and I'm wondering if that may be causing problems (I'm new to annotations and I can't say I understand exactly how they work). The reason I suspect that this might be the case, is that If I create plain (POJO) versions of the classes in question and manually build a list of those using the class instances returned by the query, then the table displays and acts correctly.
So, is there something about the BeanItemContainer that would prevent it from working in the way I am using it (and I should be doing something different), or am I just coding it incorrectly or is there not enough information in the above to say?
It's really hard to say anything about this without seeing the actual code. You did, however, say that classes are returned? The BeanItemContainer can only contain one type of class.
If you have a small test application that shows the problem, it'd be much easier to see what's wrong.
Jonatan Kronqvist: It's really hard to say anything about this without seeing the actual code. You did, however, say that classes are returned? The BeanItemContainer can only contain one type of class.
I'm querying a child table which has a foreign key link to a parent table, which in turn has a foreign key link to a grandparent table. So, each instance of the child table class has an instance of it's parent's class which in turn has an instance of the grandparent class.
Jonatan Kronqvist: If you have a small test application that shows the problem, it'd be much easier to see what's wrong.
I thought I might need to do that. :) I'll see what I can put together.
I've finally been able to get back to this, and sure enough, I was not able to reproduce the problem with a small example. :*) I had made changes to my persistence classes in the application where the problem was occurring, so I made copies of those classes, removed them and then recreated them (I'm using NetBeans, so this was easily done with the "Entity Classes from Database" function -- which was how I had created them in the first place). With the newly created persistence classes, the problem goes away. So, it must have been a coding error on my part -- now I just need to figure out what it was. :)