I am developing a web application based on Hibernate, Spring and Wicket.
So far I have implemented business objects and retention level. The transaction is controlled by the transactional interceptor of the Spring structure. Therefore, each method of the DAO classes is encapsulated in a transaction. Implementing this with the unit test was straightforward.
Now I come to the part of the web application where I also use Spring for dependency injection. Along with the @SpringBean annotations of the Wicket framework, I introduce DAO into the Wicket components. But since I'm fairly new to Wicket, I got a little stuck using the right model for my business objects when the Wicket components pass them.
I tried LoadableDetachableModel but ran into some problems. I got one page for creating a new or editing an existing business object depending on the input parameters of the page. If there is an identifier in the parameters, then the corresponding business object must be loaded from the database. When there are no parameters, you need to create a new business object. This part should have been edited, but you need to create a new object, and I will fill in the web form and click "Save", I get a NullPointerException. After some debugging, I found that the LoadableDetachableModel could not return an instance of the business object, since the overridden load () method could not load the database object form, since it had not yet been saved and therefore had no identifier.
So now I am wondering how to solve this problem. Is LoadableDetachableModel the right choice? Is it desirable to divide the form into two interdependent forms, and each form uses a different model. So, only the edit page / form uses the LoadableDetachableModel?
source share