I'll repeat my plea for patience as I'm new to Java and Wicket, but have some
minimal experience with ASP.net forms (not MVC). I've reached that point in the
learning process where I want to interact with a database and I wish to use
entities and Hibernate to make it easier. From what I've seen in various blogs
and forums, some say you shouldn't use entities as models, yet others do it
with LDMs. Since I'm taking baby steps, I want to start by using entities as
models, unless someone convinces me I'm wasting my time. Following the basic
Hibernate tutorials for persisting simple classes, I've managed to make the
following work in Wicket. In the LDM load... @Override
public Person load()
{
Session session = WicketApp.sessionFactory.openSession();
session.beginTransaction();
Person person = (Person) session.get(Person.class, 1L);
session.getTransaction().commit();
session.close();
return person;
} In the form I update the evil entity model with text boxes, using a CPM
containing the LDM. In the submit button... public void onSubmit()
{
Session session = WicketApp.sessionFactory.openSession();
session.beginTransaction();
session.update(ldm.getObject());
session.getTransaction().commit();
session.close(); this.setResponsePage(EndPage.class);
} The sessionFactory is a static member of the WicketApp application class,
initialized in the init() method. This seems to work, but I suppose there are
all kinds of faulty design patterns used here. My main concern is... how can I
do this without opening a new Hibernate session in onSubmit()? During postback,
I think I should be able to reuse the same session opened at ldm.load() in
onSubmit() also, as it all occurs in the same request. Is this possible? Thanks
for your assistance. Please feel free to point out every flaw.