Я пытаюсь вставить простую базу с 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 Bean:
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);