To avoid having detached objects in your web layer, try wrapping wicket filter with the Spring OpenSessionInView <http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/OpenSessionInViewFilter.html>filter, in that way transaction will be bound to the -> HttpRequest -> HttpResponse cycle, or you can you use a more wicket way and override onBeginRequest / onEndRequest to do your transaction work there.
On Fri, Aug 12, 2011 at 5:52 AM, Florian B. [via Apache Wicket] < ml-node+3738252-887758337-65...@n4.nabble.com> wrote: > I'm developing a web application based on Hibernate, Spring and Wicket. > > Until now I implemented the business objects and the persistence layer. The > transaction is managed by a transaction interceptor of the Spring framework > and the HibernateTransactionManager. So each method of the DAO classes is > encapsulated in a transaction. Implementing this together with unit test was > straight forward. > > Now I come to the web application part where I also use Spring for > dependency injection. Together with the @SpringBean annotations of the > Wicket framework I inject the DAOs in the Wicket components. But as I'm > pretty new to Wicket I'm a little bit stuck when using the right model for > my business objects when passing them do the Wicket components. The problem > is that I got a lot of exceptions due to detached business objects, which > are not connected to the Hibernate session any more. > > I tried to use the LoadableDetachableModel solve the issues. I put the > business object into a LoadableDetachableModel which I put into a > CompoundModel which then is bound to Form. The form is on a page which > should be used to create new business objects and also to edit exiting ones > depending on the input parameters of the page. > > If there is a id in the parameters then the corresponding business object > should be loaded from the database. When there are no parameters then a new > business object should be created. The part were a object should be edited > runs quite well but when a new object should be created, and I fill out the > web form and press save, I get a NullPointerException. After some debugging > I found out that LoadableDetachableModel could not return an instance of the > business object as the overridden load() method could not load the object > form the database as it was not saved there yet and therefore has no id. > > So now I'm wondering how to solve this problem. Is the > LoadableDetachableModel the right choice? Is it advisable to separate the > form into two interdependent forms and each form uses a different model. So > only the edit page/form uses the LoadableDetachableModel? > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > > http://apache-wicket.1842946.n4.nabble.com/How-to-use-the-LoadableDetachableModel-in-a-Wicket-Spring-Hibernate-based-web-application-correctly-tp3738252p3738252.html > To start a new topic under Apache Wicket, email > ml-node+1842946-398011874-65...@n4.nabble.com > To unsubscribe from Apache Wicket, click > here<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1842946&code=amNnYXJjaWFtQGdtYWlsLmNvbXwxODQyOTQ2fDEyNTYxMzc3ODY=>. > > -- JC -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-use-the-LoadableDetachableModel-in-a-Wicket-Spring-Hibernate-based-web-application-correctly-tp3738252p3739173.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org