Wicket-Guice and Warp-Persist
This week I came across Warp-Persist, which provides transactional persistence support with Google Guice and Hibernate. To be honest its quite like what Spring provides, but via Guice, which means no nasty XML config files (except for the hibernate one if desired).
I had already been looking at the wicket-guice project which provides support for Guice in Wicket.
The best place to start with integrating these components would be Peter Mularien’s blog post on integrating warp-persist and wicket (but not wicket-guice). Peter’s post, while good, does not cover all of the things that I had to do to get everything working.
- Add the wicket-guice jar file to your project, if you are using maven then you can easily add the dependancy to your pom.xml file, if not then I think the right jar files (you need wicket-ioc.jar too) are come with the wicket download.
- Also add the warp-persist jar file which can be obtained here (You don’t have to checkout and build the code yourself). I couldn’t find a maven repo with the warp-persist jar in it so If anyone can point me to one I would be grateful.
- You will also need the AOP alliance jar file, or you can add it to your maven pom.xml.
- In your WebApplication.init() method add the call to the GuiceComponentInjector:
injector = Guice.createInjector(PersistenceService.usingHibernate() .across(UnitOfWork.REQUEST).transactedWith( TransactionStrategy.LOCAL).buildModule(), new MyApplicationModule()); addComponentInstantiationListener(new GuiceComponentInjector(this, injector));
Make sure that you pass your injector into the GuiceComponentInjector constructor, otherwise things dont work later on (this took me several hours to figure out
) - Follow the rest of Peters instructions
- But make sure that you put the Warp-Filter before the Wicket-Filter. Putting it after did not work for me, its possible that the warp-persist code has changed between Peter’s post and now, or that wicket-juice causes something to go wrong.
- Thats it. You can get a guice injected hibernate session like this:
@Inject Provider<Session> session; @Transactional public void save(T object) { session.get().saveOrUpdate(object); }Wherever you need it.
So now you should have a nice warped guicy wicket app (sorry couldn’t resist)
Next time, integrating dynamic finders.












April 20th, 2008 at 8:00 am
Hi
Glad you like warp-persist =)
I mention in the docs that the filter must appear above other filters (I should probably make it clearer). The maven repo is also something I have been meaning to do for some time.
Would a wicket-specific doc-section have helped?
Can’t wait to see your experience with Dynamic Finders!
Dhanji.
April 20th, 2008 at 12:54 pm
I saw it in your docs that the filter should come first, its just the other post I read said it should come after the wicket one, so that’s where the confusion came from.
A wicket-specific section might have helped, but to be honest the thing that slowed me down was not realising that I needed to pass the Guice injector into the wicket-guice Component Listener.
April 20th, 2008 at 2:29 pm
Thanks for the post! I admit it’s been a while since I’ve picked up wrap-persist and Guice, but it’s nice to see a good intro like yours show up
August 17th, 2008 at 5:20 pm
[...] this year I wrote a post on integrating wicket and warp persist, and I thought it was about time I posted an update, but this time I included working example [...]