Re: Struts2 + Spring/Hibernate
Seems fine with me. CRANFORD, CHRIS wrote: !-- actions -- bean id=personAction scope=prototype class=com.company.app.struts2.actions.PersonAction constructor-arg ref=personService/ /bean I don't see any advantage on creating Actions with Spring. It works fine without it and it seems unnecessary configuration. Perhaps someone else can point out clear advantages of this. CRANFORD, CHRIS wrote: 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 I would suggest using wildcards to reduce the configuration of your actions, and also giving your actions a better name for when you have more than one domain class (otherwise you don't know if list is related to Person or to Address). For example: package name=persons namespace=/persons extends=struts-default action name=*-* class={1}Action method={2} result name=success/WEB-INF/pages/{1]/{2}.jsp/result /action /package This example would allow any action named Something-someaction to be mapped to method someaction of class SomethingAction and have a result of pages/Something/someaction -- View this message in context: http://old.nabble.com/Struts2-%2B-Spring-Hibernate-tp26329368p26333817.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts2 + Spring/Hibernate
Hi, I've just created similar skeleton couple of days ago. To let Spring generate your Service and DAO beans, you have to specify also the GenericService and GenericDAO in your applicationContext xml. You (can) set them as abstract and you have to specify the inheritance relationship between the PersonDAO and GenericDAO, the same for Service of course. At least this worked for me... Regarding your design... I thought that DAO design pattern is here to handle access to data objects, i.e. CRUD. So I don't see the benefit of the Service here? Can someone explain this? In my application I don't have any business logic but CRUD. Is the Service layer needed here or can DAO act as the Service as well? And finally I've got one more question, which I believe is related to this... One thing everyone suggest is to use wildcards in the Struts2 web.xml for CRUD operations. But this reference to many action classes with the same functionality. My question is, if we remove the duplicity in web.xml, can't we remove the duplicity in the Java code as well? Can't we create generic CRUD action as well? (Similar to generic DAO or generic Service). Thanks, Jozef On Fri, Nov 13, 2009 at 12:47 AM, CRANFORD, CHRIS chris.cranf...@setech.com wrote: 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 GenericDAOPerson,Integer { public ListPerson 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 GenericServicePerson 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
RE: Struts2 + Spring/Hibernate
Hi Wild Oscar, thanks for your input. First, I agree my design needs work with respect to naming conventions and thank you for the suggestions. This was more of a very crude example of how I should be relating components in the Hibernate/Spring/Struts2 design pattern so I can grasp the concept. In my Struts1.2 days, we didn't leverage spring nor hibernate and wrote our own DAO object framework. While it worked nicely, Hibernate has far more benefits. Now taking the example deeper, lets assume that Person is also related to two other tables in my database. For example, one table that stores Payroll and another that stores MenuPermissions. I would need to create two additional Entity objects, create their DAO and Service layers and then in all three entity objects, I would need to annotate the relationship amongst the 3 tables, correct? When I finally get to the point where this framework will hit the road is when I will have 4 or 5 tables in a database, all with relevant information about a key record or set of records in the main table and I will need to join all these records together. In the past we typically created a single record object for each query we had and while that worked nicely, there were lots of duplicity that I aim to avoid. Is this the right path and expectation for hibernate/spring/struts when I have a join between multiple database tables? Chris -Original Message- From: wild_oscar [mailto:mig...@almeida.at] Sent: Fri 11/13/2009 3:42 AM To: user@struts.apache.org Subject: Re: Struts2 + Spring/Hibernate Seems fine with me. CRANFORD, CHRIS wrote: !-- actions -- bean id=personAction scope=prototype class=com.company.app.struts2.actions.PersonAction constructor-arg ref=personService/ /bean I don't see any advantage on creating Actions with Spring. It works fine without it and it seems unnecessary configuration. Perhaps someone else can point out clear advantages of this. CRANFORD, CHRIS wrote: 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 I would suggest using wildcards to reduce the configuration of your actions, and also giving your actions a better name for when you have more than one domain class (otherwise you don't know if list is related to Person or to Address). For example: package name=persons namespace=/persons extends=struts-default action name=*-* class={1}Action method={2} result name=success/WEB-INF/pages/{1]/{2}.jsp/result /action /package This example would allow any action named Something-someaction to be mapped to method someaction of class SomethingAction and have a result of pages/Something/someaction -- View this message in context: http://old.nabble.com/Struts2-%2B-Spring-Hibernate-tp26329368p26333817.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: struts2+spring+hibernate, objects instantiate order?
1) is correct. I can't tell you the number of times that, on app startup, I've gotten reams and reams of error messages because Spring couldn't instantiate some bean or another.2) is both -- which you could determine for yourself pretty easily by putting a logging statement in the action's constructor. jk On Wed, May 13, 2009 at 10:03 PM, ren sky byzh...@gmail.com wrote: 1) before running my project, spring has already instantiate all the object defined in the applicationContext.xml? such as LoginAction,PersonServiceImpl and sessionFactory? 2) the action used in struts2 is instantiated before a request comes in? or is instantiated when a real request comes in? 3) with spring,what is the role of struts2 ? it seems that the responsibility of instantiate object is changed to spring, not struts2. thanks. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org -- Jim Kiley Senior Technical Consultant | Summa [p] 412.258.3346 http://www.summa-tech.com
Re: struts2+spring+hibernate, objects instantiate order?
ren sky wrote: 1) before running my project, spring has already instantiate all the object defined in the applicationContext.xml? such as LoginAction,PersonServiceImpl and sessionFactory? Singletons probably are, sure. 2) the action used in struts2 is instantiated before a request comes in? or is instantiated when a real request comes in? Yes. IIRC Spring will try to instantiate objects on startup to make sure they can be instantiated as defined (I could be wrong about that). Actions are definitely created per-request (assuming they're prototype scope, which they should be). 3) with spring,what is the role of struts2 ? it seems that the responsibility of instantiate object is changed to spring, not struts2. Struts 2 is the web layer. You know, handling requests. Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: Struts2+Spring+Hibernate+Oracle: ORA-12516 (too many connections)
--- On Mon, 11/24/08, scho [EMAIL PROTECTED] wrote: Normally, accessing my database isn't a problem. Hibernate saves my objects and executes my queries against the database as well. But here's my problem: I have to import a huge amount of data into my database via a CSV-File. There are about 15.000 rows and each row has to be splitted into several tables. After ~10 rows of processing an error occurs, which says: Listener refused the connection with the following error: [...] I'd probably pursue this on an Oracle list/forum; I'm not sure this is really a Struts issue. Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: struts2+Spring+Hibernate Integration
Hi, In the link provided below,it uses struts1+hibernate+spring.I have done tht and trying to do the same application in struts2.So now i have a jsp page to enter user details and to register and after clicking on submit button entered values should be saved into database for which I have used mapping files(hbm.xml) and connected to database using hibernate alone(hibernate.cfg.xml file).I am not injecting springs as of now inorder to connect to database,instead i have used hibernate pooling.I would like to use spring webservices while logging into the application after this registration process,but vill come to tht later. My present problem is after writing struts.xml,jsp pages,java class with all fields in the table and mapping hbm.xml file, I would like to insert entered details into database using hibernate i.e., I need to get the entered details and to set it to the java class(form bean kind of),so that i can send them to the hibernate dao implementation inorder to save the values.But how to get the user entered values and for what i have to set them?Since action form concept is not there in struts2.I can provide u with the code if required.. Looking forward to get a favourable hint.Plz reply as soon as possible. Thanks. Deepak Kumar wrote: Hi, Here is and application with example code http://www.roseindia.net/struts/hibernate-spring/index.shtml Thanks -Original Message- From: RajiR [mailto:[EMAIL PROTECTED] Sent: Thursday, February 21, 2008 4:04 PM To: user@struts.apache.org Subject: struts2+Spring+Hibernate Integration Hi, As struts2 comes along with spring integration with struts2-spring-plugin-2.0.11.jar,after starting the tomcat server its unable to load that jar and getting an exception as: SEVERE: Exception starting filter struts2 Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean - jar:file:/E:/Struts2WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core /tmp0/wtpwebapps/SampleStruts2/WEB-INF/lib/struts2-spring-plugin-2.0.11.jar! /struts-plugin.xml:30:132 . Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware at java.lang.ClassLoader.defineClass1(Native Method) ..com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.regi ster(XmlConfigurationProvider.java:180) ... 24 more What is the reason for this?I have checked whether I have loaded same jar double times,but tht's not tht problem.what might b the reason?Does any body came across this one? Also,the link: http://www.roseindia.net/struts/hibernate-spring/integrate.shtml helps in integrating struts1+hibernate+springs.But, since I would like to work with struts2+Hibernate+Spring,what modifications I have to do to satisfy my requirement?Since action forms concept is not there in struts2...!!! Thanks. -- View this message in context: http://www.nabble.com/struts2%2BSpring%2BHibernate-Integration-tp15607260p15 607260.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/struts2%2BSpring%2BHibernate-Integration-tp15607260p15708410.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: struts2+Spring+Hibernate Integration
Hi, By implementing Preparable,ModelDriven,ServletRequestAware interfaces,am able to get the form details and sent those details to service implementation layer from an action class.From service implementation i have called dao.Since DAO is not injected any where in struts.xml,its throwing nullpointerexception.I have used only hibernate.Is it required to use springs inorder to inject dao?Or,can I inject using hibernate and struts2 alone?? Replies pl Thanks. RajiR wrote: Hi, In the link provided below,it uses struts1+hibernate+spring.I have done tht and trying to do the same application in struts2.So now i have a jsp page to enter user details and to register and after clicking on submit button entered values should be saved into database for which I have used mapping files(hbm.xml) and connected to database using hibernate alone(hibernate.cfg.xml file).I am not injecting springs as of now inorder to connect to database,instead i have used hibernate pooling.I would like to use spring webservices while logging into the application after this registration process,but vill come to tht later. My present problem is after writing struts.xml,jsp pages,java class with all fields in the table and mapping hbm.xml file, I would like to insert entered details into database using hibernate i.e., I need to get the entered details and to set it to the java class(form bean kind of),so that i can send them to the hibernate dao implementation inorder to save the values.But how to get the user entered values and for what i have to set them?Since action form concept is not there in struts2.I can provide u with the code if required.. Looking forward to get a favourable hint.Plz reply as soon as possible. Thanks. Deepak Kumar wrote: Hi, Here is and application with example code http://www.roseindia.net/struts/hibernate-spring/index.shtml Thanks -Original Message- From: RajiR [mailto:[EMAIL PROTECTED] Sent: Thursday, February 21, 2008 4:04 PM To: user@struts.apache.org Subject: struts2+Spring+Hibernate Integration Hi, As struts2 comes along with spring integration with struts2-spring-plugin-2.0.11.jar,after starting the tomcat server its unable to load that jar and getting an exception as: SEVERE: Exception starting filter struts2 Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean - jar:file:/E:/Struts2WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core /tmp0/wtpwebapps/SampleStruts2/WEB-INF/lib/struts2-spring-plugin-2.0.11.jar! /struts-plugin.xml:30:132 . Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware at java.lang.ClassLoader.defineClass1(Native Method) ..com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.regi ster(XmlConfigurationProvider.java:180) ... 24 more What is the reason for this?I have checked whether I have loaded same jar double times,but tht's not tht problem.what might b the reason?Does any body came across this one? Also,the link: http://www.roseindia.net/struts/hibernate-spring/integrate.shtml helps in integrating struts1+hibernate+springs.But, since I would like to work with struts2+Hibernate+Spring,what modifications I have to do to satisfy my requirement?Since action forms concept is not there in struts2...!!! Thanks. -- View this message in context: http://www.nabble.com/struts2%2BSpring%2BHibernate-Integration-tp15607260p15 607260.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- View this message in context: http://www.nabble.com/struts2%2BSpring%2BHibernate-Integration-tp15607260p15715059.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: struts2+Spring+Hibernate Integration
Hi, Here is and application with example code http://www.roseindia.net/struts/hibernate-spring/index.shtml Thanks -Original Message- From: RajiR [mailto:[EMAIL PROTECTED] Sent: Thursday, February 21, 2008 4:04 PM To: user@struts.apache.org Subject: struts2+Spring+Hibernate Integration Hi, As struts2 comes along with spring integration with struts2-spring-plugin-2.0.11.jar,after starting the tomcat server its unable to load that jar and getting an exception as: SEVERE: Exception starting filter struts2 Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean - jar:file:/E:/Struts2WorkSpace/.metadata/.plugins/org.eclipse.wst.server.core /tmp0/wtpwebapps/SampleStruts2/WEB-INF/lib/struts2-spring-plugin-2.0.11.jar! /struts-plugin.xml:30:132 . Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware at java.lang.ClassLoader.defineClass1(Native Method) ..com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.regi ster(XmlConfigurationProvider.java:180) ... 24 more What is the reason for this?I have checked whether I have loaded same jar double times,but tht's not tht problem.what might b the reason?Does any body came across this one? Also,the link: http://www.roseindia.net/struts/hibernate-spring/integrate.shtml helps in integrating struts1+hibernate+springs.But, since I would like to work with struts2+Hibernate+Spring,what modifications I have to do to satisfy my requirement?Since action forms concept is not there in struts2...!!! Thanks. -- View this message in context: http://www.nabble.com/struts2%2BSpring%2BHibernate-Integration-tp15607260p15 607260.html Sent from the Struts - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: struts2+Spring+Hibernate Integration
Hi, Download Spring 2 libraries and put in your WEB-INF/lib folder Regards -- Lukasz http://www.linkedin.com/in/lukaszlenart - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]