I’m new to website development using Java but I’ve got started with Wicket and make a little website. I’d like to expand on what I’ve already made (a website with a form, labels and links) and implement database connectivity.
I’ve looked at a couple of examples, in example Mystic Paste, and I see that they’re using Hibernate and Spring. I’ve never touched Hibernate or Spring before and to be honest the heavy use of annotations scare me a little bit as I haven’t really made use of them before, with the exception of supressing warnings and overriding.
At this point I have one Connection object which I set up in the WebApplication class upon initialization. I then retrieve this connection object whenever I need to perform queries. I don’t know if this is a bad approach or not for a production web application.
All help is greatly appreciated.
Wicket, Spring and Hibernate is pretty much the standard stack for Wicket applications. Or let’s rather say that any web framework, Spring and Hibernate is pretty much the standard stack for any web framework.
Regarding Wicket, injecting objects using
@SpringBeaninside components is an extremely nice to have feature. Additionally, the OpenSessionInViewFilter manages Hibernate sessions for you (while Hibernate itself takes care of connections).Therefore, I’d really suggest you look into Spring and Hibernate – both of which don’t require annotations, but they are most of the time easier to use than configuration files (typically XML).
If you still don’t want to use Spring or Hibernate, I’d suggest you look at the OpenSessionInViewFilter and create something similar yourself: create a connection for each request, use it during one request, close it at the end. As this won’t perform very well, you might rather choose to get connections from a pool to which you return it at the end of a request. But instead of writing this code, you could already be injecting beans into your components 😉