I am in the process of implementing Struts2 along with integrated support with Spring and Hibernate. While I have found various examples on the web, I tend to find they vary. My application will primarily focus about 75% of the time on data queries and displaying this data to end users while a smaller 25% will actually support a full CRUD based system for certain data records.
So far the examples I have seen have focused on implementing a class structure similar to the following: com.company.app.hibernate.dao.PersonDAO.java com.company.app.hibernate.dao.GenericDAO.java com.company.app.hibernate.model.Person.java com.company.app.hibernate.service.PersonService.java com.company.app.hibernate.service.GenericService.java com.company.app.struts2.actions.PersonAction.java The GenericDAO class is a template-like class that holds a reference to the EntityManager along with methods for saving, deleting, and retreiving objects persisted inside the EntityManager. The PersonDAO object extends GenericDAO and provides an additional list method shown below: public class PersonDAO extends GenericDAO<Person,Integer> { public List<Person> list(int page, int size) { Query query = this.em.createQuery("from Person order by lastName, firstName"); query.setFirstResult((page-1) * size); query.setMaxResults(size); return query.getResultList(); } } The Person class itself is annotated as an @Entity object with a unique property that is marked as the entity's unique ID and all the properties of the Person table along with get/set methods for each property. GenericService is another template-like interface class that defines create/delete/update/getById/list methods. Then PersonService implements this GenericService interface with calls to the PersonDAO object for each of these methods. And lastly PersonAction extends ActionSupport and implements StrutsStatics where it gets constructed with the GenericService<Person> class. Inside my web\WEB-INF\myAppContext.xml file I have: <!-- daos --> <bean id="personDao" class="com.company.app.hibernate.dao.PersonDAO"/> <!-- services --> <bean id="personService" class="com.company.app.hibernate.service.PersonService"> <property name="dao" ref="personDao"/> </bean> <!-- actions --> <bean id="personAction" scope="prototype" class="com.company.app.struts2.actions.PersonAction"> <constructor-arg ref="personService"/> </bean> Is there anything else I should include in myAppContext.xml? Any special inclusions or statements I need in my applicationContext.xml? Per one example I saw, struts.xml should be as follows: <package name="persons" namespace="/persons" extends="struts-default"> <action name="list" class="personAction" method="list"> <result name="success">/WEB-INF/pages/persons/list.jsp</result> </action> </package> Thus far this example seemed easy to understand, particularly because we're only dealing with a single table. Before I go into how to take this example and build from it, do any of you have any input or suggestions on the approach I am taking with objects? Any lessons learned? Thanks Chris --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org