dataTable and JPA transactions

UI Components for JSF
Post Reply
Steven.Rudolf
Posts: 4
Joined: 18 Jul 2011, 11:37

18 Jul 2011, 12:09

Hello,

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 this call the "main data" are present but the lazy data from the joined tables are not read from the database at the moment.
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.

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

18 Jul 2011, 13:42

Using an extended persistence manager for this might solve things... Just experimenting with this myself

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Malcolmtoige and 26 guests