Pongo un ejemplo de lo que tengo por si alguien puede echarme una mano porque estoy ya muy bloqueado.
applicationContext
Código:
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/prueba?zeroDateTimeBehavior=convertToNull</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>contraseña</value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="myDataSource" /> </property> <!-- Must references all OR mapping files. --> <property name="mappingResources"> <list> <value>Persona.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.connection.pool_size">1</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create</prop> <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop> <prop key="hibernate.c3p0.acquire_increment">1</prop> <prop key="hibernate.c3p0.idle_test_period">100</prop> <prop key="hibernate.c3p0.max_size">5</prop> <prop key="hibernate.c3p0.max_statements">10</prop> <prop key="hibernate.c3p0.min_size">3</prop> <prop key="hibernate.c3p0.timeout">200</prop> <prop key="hibernate.c3p0.validate">SELECT 1</prop> </props> </property> </bean> <bean class="com.javierapps.controller.PersonaController" id="personaController"> <property name="personaDaoImp" ref="personaDaoImp"></property> </bean> <bean class="com.javierapps.dao.impl.PersonaDaoImp" id="personaDaoImp"> <property name="sessionFactory"> <ref local="sessionFactory"/> </property> </bean>
En esta parte si elimino el acceso a la base de datos en el metodo referenceData el problema desaparece
PersonaController.java
Código:
PersonaDaoImp.javapublic class PersonaController extends SimpleFormController { private PersonaDaoImp personaDaoImp; public void setPersonaDaoImp(PersonaDaoImp personaDaoImp) { this.personaDaoImp = personaDaoImp; } public PersonaController() { //Initialize controller properties here or //in the Web Application Context setCommandClass(Persona.class); setCommandName("persona"); setSuccessView("index"); setFormView("nuevaPersona"); } // @Override // protected void doSubmitAction(Object command) throws Exception { // throw new UnsupportedOperationException("Not yet implemented"); // } //Use onSubmit instead of doSubmitAction //when you need access to the Request, Response, or BindException objects @Override protected ModelAndView onSubmit( HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { Persona p = (Persona) command; personaDaoImp.save(p); ModelAndView mv = new ModelAndView(getSuccessView()); //Do something... return mv; } @Override protected Map referenceData(HttpServletRequest request) throws Exception { List<Persona> personas = personaDaoImp.getPersonas(); List listaNombres = new ArrayList(); for(int i=0;i<personas.size();i++){ listaNombres.add(personas.get(i).getNombre());/*Si elimino este acceso a BD el problema desaparece*/ } Map m = new HashMap<Object, Object>(); m.put("listaNombres", listaNombres); return m; } }
Código:
Espero vuestra ayuda, muchas gracias public class PersonaDaoImp extends HibernateDaoSupport implements PersonaDaoHibernate { @Override public void save(Persona persona) { this.getSession().save(persona); } @Override public List getPersonas() { Criteria c = getSession().createCriteria(Persona.class); return c.list(); }