Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法使用spring jdbc NamedParameterJdbcTemplate以批处理方式存储枚举_Java_Spring_Enums_Spring Jdbc_Jdbctemplate - Fatal编程技术网

Java 无法使用spring jdbc NamedParameterJdbcTemplate以批处理方式存储枚举

Java 无法使用spring jdbc NamedParameterJdbcTemplate以批处理方式存储枚举,java,spring,enums,spring-jdbc,jdbctemplate,Java,Spring,Enums,Spring Jdbc,Jdbctemplate,我面临SpringJDBC的枚举问题。我有一个包含枚举值的POJO。我想在数据库中存储字符串值,而不是序号。我制作了一个DAO,除了使用命名参数jdbcTemplate的批处理方法(对于jdbcTemplate和BatchPreparedStatementSetter,它可以工作,但我更喜欢使用命名参数)之外,它工作得很好 例如: public int[] batchUpdate(List<MyPojo> pojos) throws DaoException { SqlPar

我面临SpringJDBC的枚举问题。我有一个包含枚举值的POJO。我想在数据库中存储字符串值,而不是序号。我制作了一个DAO,除了使用命名参数jdbcTemplate的批处理方法(对于jdbcTemplate和BatchPreparedStatementSetter,它可以工作,但我更喜欢使用命名参数)之外,它工作得很好

例如:

public int[] batchUpdate(List<MyPojo> pojos) throws DaoException {
    SqlParameterSource[] parameters = new SqlParameterSource[pojos.size()];

    for (int i = 0; i < pojos.size(); i++) {
        parameters[i] = new BeanPropertySqlParameterSource(pojos.get(i));
    }

    try {
        return namedParameterJdbcTemplate.batchUpdate(SQL_UPDATE, (SqlParameterSource[]) parameters);
    } catch (Exception ex) {
        throw new DaoException(ex);
    }
}
public int[]批处理更新(列表POJO)引发异常{
SqlParameterSource[]参数=新的SqlParameterSource[pojos.size()];
对于(int i=0;i
不适用于枚举属性

我有一个错误:

原因:org.h2.jdbc.JdbcSQLException:列的值太长 “状态字符变化(20)不为空”: “'ACED0057E7200466F72672E67656E792E7064702E66976562697264732E67656E79746F74652E646F6D61696E6D6D6F64656C2E6265742E4265744465636F6…”。。。 (258)"; SQL语句:更新。。。设置…,状态=?其中id=?[22001-187]在 org.h2.message.DbException.getJdbcSQLException(DbException.java:345) 位于org.h2.message.DbException.get(DbException.java:179) org.h2.table.Column.validateConvertUpdateSequence(Column.java:327)位于 org.h2.table.table.validateConvertUpdateSequence(table.java:737)位于 org.h2.command.dml.Update.Update(Update.java:125)位于 org.h2.command.CommandContainer.update(CommandContainer.java:78)位于 org.h2.command.command.executeUpdate(command.java:254)位于 org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:157) 在 org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1183) 在 org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:1005) 在 org.springframework.jdbc.core.JdbcTemplate$4.doInPreparedStatement(JdbcTemplate.java:989) 在 org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:644) ... 43多

MyPojo有一个枚举值(状态)。这很奇怪,因为我要存储的枚举字符串是“已验证”而不是“aced000…”。如果我使用JPA,我会使用
@Enumerated(EnumType.STRING)
作为我的状态字段,但是SpringJDBC上是否存在类似的东西


关于通过注册sql类型最终解决的问题:

    for (int i = 0; i < bets.size(); i++) {
        BeanPropertySqlParameterSource bpsps = new BeanPropertySqlParameterSource(pojos.get(i));
        bpsps.registerSqlType("status", Types.VARCHAR);
        parameters[i] = bpsps;
    }
for(int i=0;i