Results 1 to 3 of 3

Thread: java.io.NotSerializableException for BeanPropertySqlParameterSource

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default java.io.NotSerializableException for BeanPropertySqlParameterSource

    Hello Guys

    I am working with:

    Spring Core 3.1.2.RELEASE, STS 3.0.0 + JDK 1.7

    I have the follow Entity

    Code:
    @SuppressWarnings("serial")
    public class Cliente implements Serializable{
    	
    	private String idCliente;
    	private String nombreCliente;
    	private String apellidoCliente;
    	private Date fechaCliente;
    
    //setters/getters
    
    //toString
    }
    the table is

    Code:
    create table cliente(
    
    	idCliente varchar(10) not null,
    	nombreCliente varchar(20) not null,
    	apellidoCliente varchar(20) not null,
    	fechaCliente timestamp not null,
      
    	PRIMARY KEY(idCliente)
    	 
    )ENGINE=InnoDB;
    Therefore same fields/variables in a 100%

    My Dao Method

    Code:
    @Transactional
    @Repository
    public class ClienteJdbcDaoImpl implements ClienteDaoService{
    	
    	@Autowired
    	private JdbcTemplate jdbcTemplate;
    	
    	@Override
    	public void insertarCliente(Cliente cliente) {
    		
    		SqlParameterSource sqlParameterSource = 
    				new BeanPropertySqlParameterSource(cliente);
    		
    		jdbcTemplate.update("INSERT INTO cliente(idCliente, nombreCliente, apellidoCliente, fechaCliente) " +
    	            		    "VALUES(:idCliente, :nombreCliente, :apellidoCliente, :fechaCliente) ",
    	            		    sqlParameterSource		            
    	            );		
    	}
    }
    My Main class

    Code:
    ClienteBoService clienteBoService =
    				(ClienteBoService) context.getBean(ClienteBoService.class);
    		
    Cliente cliente = new Cliente();
    	
    cliente.setIdCliente("MJE");
    cliente.setNombreCliente("Manuel");
    cliente.setApellidoCliente("Jordan");
    cliente.setFechaCliente(new Date());
    	
    clienteBoService.insertarCliente(cliente);
    But when I execute the code I always get

    Code:
    Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
            ...
    	... 28 more
    Caused by: java.io.NotSerializableException: org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource
    	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    	at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:4393)
    	... 38 more
    What is wrong?

    I did the same than the code used in Spring Recipes 2nd Edition, the unique difference is that in the book it is working with the SimpleJdbcTemplate class where it is now deprecated and the API suggest use the jdbcTemplate.
    I am doing this

    Even more, even If use

    Code:
    Map<String, Object> parameters = new HashMap<String,Object>();
    		
    parameters.put("idCliente", cliente.getIdCliente());
    parameters.put("nombreCliente",cliente.getNombreCliente());
    parameters.put("apellidoCliente",cliente.getApellidoCliente());
    parameters.put("fechaCliente",cliente.getFechaCliente());
    		
    SqlParameterSource sqlParameterSource = 
    		new MapSqlParameterSource(parameters);
    I got the same results

    What is wrong?

    Thanks in advanced
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I suggest a read of the docs ...

    JdbcTemplate doesn't have a method which uses a SqlParameterSource only the NamedParameterJdbcTemplate has one...

    What is wrong?
    Using the wrong template...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello Marten

    Have sense your idea, I will check it out tonight or tomorrow

    Thank You.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •