Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

subha nair

Greenhorn
+ Follow
since Jun 19, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by subha nair

Hi ,
I am currently doing a project for the same..
We are developing a prototype..
check this out
http://www.techfaq360.com/tutorial/spring/struts_spring_hibernate.jsp
I am doing struts in the web tier, springs and hibernate.

applicationContext.xml
========================

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:aop="http://www.springframework.org/schema/aop";
xmlns:tx="http://www.springframework.org/schema/tx";
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/shop</value>
</property>
<property name="username">
<value>palnar</value>
</property>
<property name="password">
<value>palnar</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>

<property name="annotatedClasses">
<list>
<value>com.palnar.shop.form.Login</value>

</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="connection.pool_size">1</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<bean id="LoginDAO"
class="com.palnar.shop.dao.LoginDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<aop:config></aop:config>
</beans>


web.xml
==========
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Shop</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>


<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!--<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/shop-servlet.xml</param-value>
</context-param>
-->

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/shop-servlet.xml</param-value>
</context-param>
-->

<servlet>
<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<!-- Standard Action Servlet Mapping -->
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<jsp-config>
<taglib>
<taglib-uri>/tags/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/tags/struts-logic</taglib-uri>
<taglib-location>
/WEB-INF/tld/struts-logic.tld
</taglib-location>
</taglib>
</jsp-config>
</web-app>

struts-cnfig.xml
===================
<?xml version="1.0" encoding="UTF-8"?>
<struts-config>



<form-beans>
<form-bean name="login" type="com.palnar.shop.form.Login" />
</form-beans>

<action-mappings>
<action path="/Login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="login">
<forward name="success" path="/success.jsp" />
<forward name="failure" path="/index.jsp" />
</action>
</action-mappings>

<!-- <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/> -->

<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml,/WEB-INF/shop-servlet.xml" />
</plug-in>


</struts-config>


===============================================================
when I run this application, I am getting the error..
servlet action not available..

please tell me a solution
thanks......
can anyone guide me through using ejb implementation using springs
please it is urgent
I have created a Customer table which has Name,id and phone
I have an embeddable class Name having firstname and lastname.

Code is as follows..

Customerbean.java
====================


============================================================================

When I run this it is giving an exception

org.apache.jasper.JasperException: Invalid property 'firstname' of bean class [com.palnar.library.service.CustomerRegistrationBean]: Bean property 'firstname' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?


Please help me in this.....
[ July 12, 2008: Message edited by: Mark Spritzler ]
Help me to do implement ejb's using spring.
Is thre any god tutorial for the same
I think I have sorted this out. Now it's not giving error.

I have added hibernate to the existing application.

applicationContext.xml
*************************

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/samplesdb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>

<property name="mappingResources">
<list>
<value>Staff.hbm.xml</value>
</list>
</property>

<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>

<bean id="StaffDAO" class="com.palnar.college.DAO.StaffDAOHibernate">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>


StaffDAOHibernate
*******************


import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.palnar.college.service.StaffReg;

public class StaffDAOHibernate extends HibernateDaoSupport implements StaffDAO{

public List getStaff() {
return getHibernateTemplate().find("from StaffReg");
}

public void saveRecord(StaffReg staffreg) {
getHibernateTemplate().saveOrUpdate(staffreg);
}

}


When I am running it is giving the below error

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate.LocalSessionFactoryBean] for bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate.LocalSessionFactoryBean


Please help me out
I am writing a spring application and has not tied hibernate to it.
The application runs fine displaying the pages.
but when I add the below lines to my web-xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>


It is showing the error.
description The requested resource (/SpringWeb/) is not available.

I think it is not able to locate the applicationcontext.xml.
Without locating that I dont think I can go with adding hibernate to it.
Please help me out..This is very urgent
Thanks for your valuable help..

I am facing a different kind of problem.

I am writing a spring application and has not tied hibernate to it.
The application runs fine displaying the pages.
but when I add the below lines to my web-xml

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>


It is showing the error.
description The requested resource (/SpringWeb/) is not available.

I think it is not able to locate the applicationcontext.xml.
Without locating that I dont think I can go with adding hibernate to it.
Please help me out..This is very urgent
Thanks for the reply...

My line 15 in StaffDAO is

getHibernateTemplate().saveOrUpdate(staffReg);

and the class is


package com.palnar.college.DAO;

import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.palnar.college.service.StaffEdit;
import com.palnar.college.service.StaffReg;

public class StaffDAO extends HibernateDaoSupport{
public void saveUser(StaffReg staffReg){

System.out.println(staffReg.getId());
System.out.println(staffReg.getName());

getHibernateTemplate().saveOrUpdate(staffReg);


}

}

Please help me out...
Hi,
I am trying to build an application in spring and hibernate.After writing the applicationContext.xml and spring xml file.
I am getting this exception
***********

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:535)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:463)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


the root cause
******************

java.lang.NullPointerException
com.palnar.college.DAO.StaffDAO.saveUser(StaffDAO.java:14)
com.palnar.college.web.StafRegController.onSubmit(StafRegController.java:26)
org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:808)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:523)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:463)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


com.palnar.college.DAO.StaffDAO.saveUser

public class StaffDAO extends HibernateDaoSupport{

public void saveUser(StaffReg staff){


getHibernateTemplate().saveOrUpdate(staff);

}

StafRegController
************************
public class StafRegController extends SimpleFormController{

@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {

StaffReg staffreg=(StaffReg)command;
StaffDAO staffdao=new StaffDAO();

staffreg.setId(staffreg.getId());
staffreg.setName(staffreg.getName());

staffdao.saveUser(staffreg);

return new ModelAndView("success");
}


applicationcontext.xml
*****************************
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/samplesdb</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.palnar.college.service.StaffReg</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="connection.pool_size">1</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate.hibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="StaffDAO"
class="com.palnar.college.DAO.StaffDAO">
<property name="sessionFactory" ><ref local="sessionFactory"/></property>
</bean>


web.xml
******************


<servlet>
<servlet-name>SpringWeb</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringWeb</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>/WEB-INF/jsp/index.jsp</welcome-file>
</welcome-file-list>

<jsp-config>
<taglib>
<taglib-uri>/spring</taglib-uri>
<taglib-location>
/WEB-INF/tld/spring-form.tld
</taglib-location>
</taglib>
</jsp-config>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
Hello,
I am trying to add hibernate to my existing spring application.I am using spring 2.5,hibernate annotations 3.2, mysql and tomcat
I have written applicationcontext.xml and hibernate.cfg.xml.
But I am getting this error

Context initialization failed.org.springframework.beans.factory.beandefinitionstoreexception: IOException parsing XML document from servletcontext resource [/web-inf/applicationcontext.xml]
nested exception is java.io.FilenotfoudException: could not open servletcontext resource [/web-inf/applicationContext.xml]


Below are the two config files

applicationContext.xml
****************************

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:aop="http://www.springframework.org/schema/aop";
xmlns:tx="http://www.springframework.org/schema/tx";
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<!-- the parent application context definition for the springapp application -->

<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/bank</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>

<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.
LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="configLocation">
<value>WEB-INF\classes\hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
<bean id="customerDAOimpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

<bean id="customerDAO" class="com.palnar.college.DAO.customerDAOHibernateImpl.java"
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>


</beans>

hibernate.cfg.xml
************************

<hibernate-configuration>
<session-factory>
<mapping package="com.palnar.college.service" />
<mapping class="com.palnar.college.service.Customer" />
</session-factory>
</hibernate-configuration>

web.xml
*************
......
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

......

PLEASE HELP ME OUT.THIS IS VERY URGENT
please help me in getting the Spring and hibernate up and running.
Please send me the steps for this.
i am using mysql database,hibernate annotations with eclipde.

please help me
I have developed a simple application in spring.
I wanted to add hibernate capabilities to it.
Can you tell how many files are needed.
I am using hibernate annotations.
do I have to write hibernate.cfg.xml and applicationcontext.xml
please help me
Thanks a lot for the reply.
In cfg.xml. I had accidently put
<property name="hbm2ddl.auto">create</property>
I changed the create to update.

Thanks.I have got another doubt.Could you sort it out

I wanted to edit the values previously stored in the database.
I am using struts with hibernate for it.
I have used a dispatchaction class where I have written add,delete and edit code.
each operation is calling another method where the database calls are done.
the vaues read from the database are stored in the arraylist, and they are passsed to the actionclass .then these are passed to jsp page to display the values.Is there any other effective
way to do the application rather than passing collection through pages. I was told that it affects performance, if session object that stores collections are passed over .
I am doing a project in struts,hibernate ,tomcat,mysql.
It is similar to library management and has all the operations add,delete,edit and search.
Earlier we were using arraylist to store the values from database for doing edit operations and we are passing this
arraylist in session to another jsp page, where these will retrieve the values stored in the session attribute and gets displayed in the
jsp page. Is there any other way to load the form when edit is clicked
12 years ago