ZK + Spring + JPA + Hibernate + lazy loaded results?

asked 2010-09-17 07:24:27 +0800

altanis gravatar image altanis


I'm using frameworks combination as described in topic.
I my project I want ZK to be talking with Spring's beans and Spring via JPA to be talking with JPA implementation - Hibernate. Everything works fine, but I have very large collection to retrieve from DB. I was thinking about some kind of lazy data loading (well, not strict definition of lazy loading or fetching, but I wanted to retrieve lazily data collection from JPA).

Here is an example:

Suppose we have listbox with paging (pageSize=10). Data is retrieved from Spring’s bean by spring variable resolver. Spring requests objects from Hibernate through JPA, suppose it is a named query, selecting all entries from table.

OK, everything works fine, I have data, paging works....but I'd like to retrieve only 10 results at once. This means that when I change page in my list box, another query to DB would be performed.

Is it possible to do this automatically? With some kind of lazy loading mechanism?

I couldn't find solution anywhere (perhaps I've been searching with wrong keywords)

Do you have any ideas how to accomplish this task?

delete flag offensive retag edit

5 Replies

Sort by » oldest newest

answered 2010-09-17 09:09:27 +0800

caclark gravatar image caclark
1753 2 5

I know of no way to do it automatically. I think you're going to have to hook the onPage event of the pager and do it yourself. I create service and DAO methods that include a beginning row # and size in case I need to do this kind of thing.

link publish delete flag offensive edit

answered 2010-09-17 10:44:14 +0800

altanis gravatar image altanis

Hi caclark,

Yes your solution sounds cool, however I was thinking about resolving this issue on entity layer.

For example create one entity with index field and reference to "real" entity (mapped one to one). From the DB point of view there would be one additional table:

ID: int (PK)

This approach + JPA lazy fetching could do the trick, because Hibernate would download data only, when needed.

I hope there is smarter solution, without making entity layer too complicated and without writing a lot of code.

link publish delete flag offensive edit

answered 2010-09-20 02:19:44 +0800

PeterKuo gravatar image PeterKuo
481 2

I'm not familiar with spring.
But zk has some example about huge data.
You may google "zk huge data" or "zk rod"

link publish delete flag offensive edit

answered 2010-09-21 10:01:30 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2010-09-21 10:02:30 +0800

To complete this thread:

There some reference how to handle this request:

1.) Smalltalk about Handling huge data using ZK
This example handles the paging event itself (like Cary's approach).

+ Grow/List is always small and contains only one page of data
- you need extra code to manage the paging -events

2.) Use own Listmodels like the zksample2 project (by terrytornado and bbruhns)
Here is the utilclass PagedBindingListWrapper

And here is the use of this class: ArticleListCtrl

+ extra coding is reduced to the minium
- most zk versions create dummy objects for all objects
i.e. the data contains i.e. 1 Mio row, ZK prepare 1 Mio (listbox/grid) empty entries [1]
(-) some people would prefer JPA objects instead of hibernate

[1] The enterprise edition (ZK 5) should be smarter (not tested, i've only read the changes) and creates only required list/rowitems

However, is should be possisble to handle this request with common util classes.


link publish delete flag offensive edit

answered 2010-09-21 13:18:57 +0800

altanis gravatar image altanis


Thank you all for your ideas and support. I think I have enough examples to implement my task.


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2010-09-17 07:24:27 +0800

Seen: 827 times

Last updated: Sep 21 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More