Here's how I do it.

I have my wicket layer call a service layer, which calls a DAO.
I'm not a big fan of a lot of layers and I like to keep my projects
flat.

So, if you want a list of users on a page, for example, you can
use any of the canned wicket tables.  Those are pretty nice.
I use DefaultDataTable unless I need something special.  So in
your page class you do something like

DefaultDataTable defaultDataTable = new DefaultDataTable("table",
columnsList, new SortableUserDataProvider(userFilter), 10);

If this doesn't make sense look at the DefaultDataTable.java class in the
wicket examples.

In my SortableUserDataProvider, I pass in a filter obj depending on what the
user
is asking for.  This includes any search criteria, sort options, paging,
etc.

My SortableUserDataProvider calls my service.  That preps the hibernate
query
and calls my dao.

So for the SortableUserDataProvider you want to override the iterator()
method,
something like:

public Iterator<User> iterator(int first, int count)
        {
                SortParam sp = getSort();

                userFilter.setFirstRecord(first);
                userFilter.setRecordsToReturn(count);
                userFilter.setSortCol(sp.getProperty());
                userFilter.setSortAsc(sp.isAscending());

                return UserService.getUsers(userFilter).iterator();
        }

I prep my queries in my service layer.  So something like

Criteria userCriteria = session.createCriteria(User.class)
.setFirstResult(filter.getFirstRecord())
//other filter info here as needed

List<User> userList = userCriteria.list();

Hibernate returns models and lists of models, and wicket
uses models and lists of models.  

The only catch with this is your web layer is getting hibernate
aware models, not POJOs.  So if it's a closed system where nobody
else hits your hibernate code, you're fine.  If the service layer
is an SOA type arch, you'll need to convert your hibernate models
(or the list), to equivalent pojos on select and vice-versa on saves.


The only thing I did which I regret was I defined my collections 
in hibernate as Lists instead of sets.  I did this because wicket 
takes a list as a param in a lot of places and Lists are generally 
easier to work with.

But hibernate treats Lists as bags and when you are doing eager fetches
on multiple collections, Hibernate will complain.  
It won't let you fetch multiple bags simultaneously.  It used to though.
They keep threatening to fix it.

http://opensource.atlassian.com/projects/hibernate/browse/HHH-1718

-- 
View this message in context: 
http://www.nabble.com/wicket-and-hibernate-tp19767474p19772328.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to