Announcement Announcement Module
Collapse
No announcement yet.
Problem with namedParameters and Spring 3.1.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with namedParameters and Spring 3.1.1

    With (deprecated and spring 2.5) SimpleJdbcDaoSupport my old program works fine...
    A new project with new version of spring do not work because then object param is empty.


    My Beans
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING/DTD BEAN/EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    	<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://192.168.1.104:3306/tb_fatture?zeroDateTimeBehavior=convertToNull</value>
    		</property>
    		<property name="username">
    			<value>username</value>
    		</property>
    		<property name="password">
    			<value>password</value>
    		</property>
    	</bean>
    	
    	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    		<constructor-arg>
    			<ref bean="dataSource"/>
    		</constructor-arg>
    	</bean>
    	
    	<bean id="UtentiDAO" class="rvl.toolbox.dao.UtentiDAO">
    		<property name="jdbcTemplate">
    			<ref bean="jdbcTemplate"/>
    		</property>
    	</bean>
    	<bean id="EventiUtenteDAO" 
    		class="rvl.toolbox.dao.EventiUtenteDAO">
    		<property name="jdbcTemplate">
    			<ref bean="jdbcTemplate"/>
    		</property>		
    		<property name="dataSource" ref="dataSource" />
    	</bean>
    
    </beans>
    My class
    Code:
    public class EventiUtente {
    
    	private Integer progressivo;
    	private String utente;
    	private java.sql.Timestamp data_evento;
    	private Integer evento;
    	
    	
    	public Integer getProgressivo() {
    		return progressivo;
    	}
    	public void setProgressivo(Integer progressivo) {
    		this.progressivo = progressivo;
    	}
    	public String getUtente() {
    		return utente;
    	}
    	public void setUtente(String utente) {
    		this.utente = utente;
    	}
    	public java.sql.Timestamp getData_evento() {
    		return data_evento;
    	}
    	public void setData_evento(java.sql.Timestamp data_evento) {
    		this.data_evento = data_evento;
    	}
    	public Integer getEvento() {
    		return evento;
    	}
    	public void setEvento(Integer evento) {
    		this.evento = evento;
    	}
    	
    	
    }
    My "offending" code
    Code:
    public class EventiUtenteDAO extends NamedParameterJdbcDaoSupport
    {
    		
    	public void insEvento(EventiUtente ev) throws org.springframework.dao.DataAccessException
    	{
    		
    		String sql = "insert into tg_eventi_utente(utente,evento,data_evento) values (:utente,:evento,:data_evento)";			
    			
    		DefaultTransactionDefinition txd = new DefaultTransactionDefinition();
    		txd.setName("EventiUtenteDAO.insert");
    		txd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    		
    		//
    		// Possono essere inseriti nuovi dati ma non puņ essere modificato il record in uso
    		//
    		txd.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
    		txd.setTimeout(50);
    		
    		DataSourceTransactionManager txManager = new DataSourceTransactionManager(getDataSource());
    		TransactionStatus status = txManager.getTransaction(txd);
    		try 
    		{
    			//SqlParameterSource param = new BeanPropertySqlParameterSource(ev);
    			//getJdbcTemplate().update(sql,param);
    			NamedParameterJdbcTemplate npjt = new NamedParameterJdbcTemplate(getDataSource());
    			SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(ev);
    			//npjt.update(sql,namedParameters);
    			npjt.queryForRowSet(sql, namedParameters);
    		}
    		catch (DataAccessException ex) 
    		{
    		  txManager.rollback(status);
    		  throw ex;
    		}
    		txManager.commit(status);	
    	}
    Why namedParameters is empty?
    Where is my error?
    I tried many way but without results...
    Thanks.
    Luca
Working...
X