I am using p:dataTable and want to show some JPA entities directly in it. These Entities comes from a datamodel with more than one table and are loaded in a lazy way.
I use this methode before rendering the view with the dataTable:
Code: Select all
public String selectContent() {
// initialize the lazy datamodel and link it with the service implementation
this.lazyDataModel = new LazyDataModel<Party>() {
@Override
public List<Party> load(final int first, final int pageSize, final String sortField,
final boolean sortOrder, final Map<String, String> filters) {
// simply call the data access object
return this.partyDao.findSelectionInRange(pageSize, first);
}
};
}
After rendering the view the User transaction is committed and the JTA transaction is closed.
Now the dataTable want's to render the data and simply try to acces the read data. Because the lazy data from the joined tables are not present the columns with this informations are empty. This is because the JTA-transaction is closed and the entities are detached from the session.
So my question is: Is there any "callback" method called before the primefaces dataTable tries to access the column values? If there is one I could open a JTA transaction and attach the entities manually to it.
I know, If any beans (view-bean and DAO-bean) are @SessionScoped then everything works fine but this is not an option for a productive application!
Further I know, I could read the data in my DAO in the way I need it on my screen. But this approach would lead to the fact that I can never use the lazy loading possibilities of JPA for the datatables.