spring - 无法找到表的表元数据

标签 spring postgresql

我正在使用 Spring,我的类使用 @Transactional 进行注释。

我正在使用 SimpleJdbcInsert 但我收到以下警告:

TableMetaDataProvider: - Unable to locate table meta data for 'data.data_insert' -- column names must be provided

我有三个表,所有三个表都具有这样的关系:

table1

primary keytable 2 中的外键primary key<表 2 中的/em> 是 表 3 中的外键

显示表 1 插入代码:

java.sql.Timestamp timestamp = getCurrentJavaSqlTimestamp();
Map<String, Object> params = new HashMap<String, Object>();
params.put("notes", task.getNotes());
params.put("recording_time", timestamp);
params.put("end_user_id", 805);
SimpleJdbcInsert insertData = new SimpleJdbcInsert(dataSource).
withTableName("data.data_insert").
usingColumns("notes", "recording_time",
"end_user_id").usingGeneratedKeyColumns("data_id");
long dataId = insertData.executeAndReturnKey(params).longValue();

错误日志:

2015-09-29 14:10:27,133  WARN [http-8080-2] LegacyFlexJsonExceptionMessageConverter: - Generated Key Name(s) not specificed. Using the generated keys features requires specifying the name(s) of the generated column(s) for User ID: 805, Request ID: f8da3bb5-0613-4a74-9ca8-95a6ab4f1692, clientIP: 127.0.0.1 uri: /admin/dataInsert, Request Parameters:
org.springframework.dao.InvalidDataAccessApiUsageException: Generated Key Name(s) not specificed. Using the generated keys features requires specifying the name(s) of the generated column(s)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert.prepareStatementForGeneratedKeys(AbstractJdbcInsert.java:530)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert.access$0(AbstractJdbcInsert.java:528)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert$1.createPreparedStatement(AbstractJdbcInsert.java:448)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:581)
        at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:843)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyHolderInternal(AbstractJdbcInsert.java:445)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert.executeInsertAndReturnKeyInternal(AbstractJdbcInsert.java:426)
        at org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecuteAndReturnKey(AbstractJdbcInsert.java:380)
        at org.springframework.jdbc.core.simple.SimpleJdbcInsert.executeAndReturnKey(SimpleJdbcInsert.java:122)
        at com.gridpoint.energy.datamodel.impl.PGDataFixBackUpManagerBean.backupDataInRange(PGDataFixBackUpManagerBean.java:79)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)

最佳答案

正确的是:

java.sql.Timestamp timestamp = getCurrentJavaSqlTimestamp();
Map<String, Object> params = new HashMap<String, Object>();
params.put("notes", task.getNotes());
params.put("recording_time", timestamp);
params.put("end_user_id", 805);
SimpleJdbcInsert insertData = new
SimpleJdbcInsert(dataSource).withSchemaName("data").
withTableName("data_insert")
usingColumns("notes", "recording_time",
"end_user_id").usingGeneratedKeyColumns("data_id");
long dataId = insertData.executeAndReturnKey(params).longValue();

所以只需要一个使用 withSchemaName 的 schemaName。

关于spring - 无法找到表的表元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32839758/

相关文章:

java - 如果超过 1 个线程访问,Spring @Cacheable 是否会阻塞?

java - Spring JPA OneToOne FK 作为 PK Cascade.Remove

java - 如何使用 JDBC 在 PostgreSQL 中传递一组复合类型 (UDT)

java - 无法实例化 bean 类 : BeanInstantiationException

spring - 使用 spring boot 配置多个 servletcontainers/servlet

恢复后 PostgreSQL 9.2 归档最后重放的 WAL

postgresql - 如何匹配not null + not empty?

Postgresql select,显示固定计数行

postgresql - postgres 中的 View 路径(其他全局可用表的私有(private)/个人版本)

java - Spring 安全 : mapping of exceptions thrown inside security filter