I've been trying to set up a little hibernate/spring MVC project.
I've gotten the Spring .jsp page to display data from the database, but i cannot figure out how to have hibernate save the objects to the database.
Here is my (relevant) Code:
GroupDAOImpl.java (the method)
@Override
public void saveGroup(Group group){
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
session.save(group);
transaction.commit();
session.close();
}
HelloController.java Method:
public ModelAndView add(HttpServletRequest request, HttpServletResponse response, Group group) throws Exception {
groupDAO.saveGroup(group);
return new ModelAndView("redirect:list.htm");
}
jsp Page:
<form:form action="add.htm" commandName="group">
<table>
<tr>
<td>group Name :</td>
<td><form:input path="name"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
Log from the Server:
Hibernate: insert into groups (id, name, shoppingList_id) values (default, ?, ?)
Debugger Value of "group" in GroupDAOImpl saving method:
id = 2
name = "jjjj"
Any ideas? Greatly appreciated!