Spring: java.io.NotSerializableException: MapSqlParameterSource
Spring: java.io.NotSerializableException: MapSqlParameterSource
我正在尝试使用 Spring JdbcTemplate
插入一个简单的基础,将参数查询与 MapSqlParamaterSource
映射,并将错误作为以下数据:
public void adiciona(Conta conta) {
String sql = "insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)";
MapSqlParameterSource pss = new MapSqlParameterSource();
pss.addValue("descricao", conta.getDescricao());
pss.addValue("paga", "true");
pss.addValue("valor", conta.getValor());
pss.addValue("tipo", conta.getTipo());
getJdbcTemplate().update(sql, pss);
}
错误日志:
mar 22, 2015 12:16:00 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [spring mvc] in context with path [/contas] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException] with root cause
java.io.NotSerializableException: org.springframework.jdbc.core.namedparam.MapSqlParameterSource
Java豆子:
public class Conta implements Serializable {
private static final long serialVersionUID = 4678852901357132238L;
private Long id;
private String descricao;
private boolean paga;
private double valor;
private Calendar dataPagamento;
private TipoDaConta tipo;
// getters and settes
谁能告诉我如何解决这个问题?
试试这样的东西:
this.getJdbcTemplate().update(updateStatement, new Object[] {conta.getDescricao(), "true", conta.getValor(), conta.getTipo()});
我也遇到了同样的问题,我把它改成
解决了
this.getJdbcTemplate().update(query,mapSqlParameterSource);
至
this.getNamedParameterJdbcTemplate().update(query,mapSqlParameterSource);
我正在尝试使用 Spring JdbcTemplate
插入一个简单的基础,将参数查询与 MapSqlParamaterSource
映射,并将错误作为以下数据:
public void adiciona(Conta conta) {
String sql = "insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)";
MapSqlParameterSource pss = new MapSqlParameterSource();
pss.addValue("descricao", conta.getDescricao());
pss.addValue("paga", "true");
pss.addValue("valor", conta.getValor());
pss.addValue("tipo", conta.getTipo());
getJdbcTemplate().update(sql, pss);
}
错误日志:
mar 22, 2015 12:16:00 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [spring mvc] in context with path [/contas] threw exception [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [insert into contas (descricao, paga, valor, tipo) values (:descricao,:paga,:valor,:tipo)]; Invalid argument value: java.io.NotSerializableException; nested exception is java.sql.SQLException: Invalid argument value: java.io.NotSerializableException] with root cause
java.io.NotSerializableException: org.springframework.jdbc.core.namedparam.MapSqlParameterSource
Java豆子:
public class Conta implements Serializable {
private static final long serialVersionUID = 4678852901357132238L;
private Long id;
private String descricao;
private boolean paga;
private double valor;
private Calendar dataPagamento;
private TipoDaConta tipo;
// getters and settes
谁能告诉我如何解决这个问题?
试试这样的东西:
this.getJdbcTemplate().update(updateStatement, new Object[] {conta.getDescricao(), "true", conta.getValor(), conta.getTipo()});
我也遇到了同样的问题,我把它改成
解决了this.getJdbcTemplate().update(query,mapSqlParameterSource);
至
this.getNamedParameterJdbcTemplate().update(query,mapSqlParameterSource);