我收到此错误
Unable to locate columns for table 'user_models' so an insert statement can't be generated
使用Spring 3.1.2。我正在维护遗留代码。并且它(抛出异常的方法)具有注释@Transactional(propagation = Propagation.REQUIRED)
。它还使用缓存并具有以下注释 @CacheEvict(value = "UserModel", key = "#userModel.id")
我在这个异常上遇到了死胡同。我只找到了一个关于此错误的链接:
https://jira.spring.io/browse/SPR-4782
我无法理解它的意义。有人至少可以引导我走向正确的方向吗?
编辑
堆栈跟踪如下:
Server Error occured while executing method [saveModel] org.springframework.dao.InvalidDataAccessApiUsageException: Unable to locate columns for table 'user_models' so an insert statement can't be generated
at org.springframework.jdbc.core.metadata.TableMetaDataContext.createInsertString(TableMetaDataContext.java:325)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compileInternal(AbstractJdbcInsert.java:282)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.compile(AbstractJdbcInsert.java:265)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.checkCompiled(AbstractJdbcInsert.java:316)
at org.springframework.jdbc.core.simple.AbstractJdbcInsert.doExecute(AbstractJdbcInsert.java:342)
at org.springframework.jdbc.core.simple.SimpleJdbcInsert.execute(SimpleJdbcInsert.java:114)
at com.capillary.recommender.model.user.data.dao.impl.UserModelDaoImpl.save(UserModelDaoImpl.java:344)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at com.capillary.common.spring.transaction.ProxyTransactionInterceptor.invoke(ProxyTransactionInterceptor.java:30)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.cache.interceptor.CacheInterceptor$1.invoke(CacheInterceptor.java:58)
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:213)
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:66)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at com.sun.proxy.$Proxy67.save(Unknown Source)
at com.capillary.recommender.model.user.UserModelStore.saveModel(UserModelStore.java:62)
at com.capillary.recommender.model.user.UserModelStore.saveModel(UserModelStore.java:19)
at com.capillary.recommender.thrift.ThriftRecommenderService.saveModel(ThriftRecommenderService.java:168)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
抛出以下错误的代码片段:
Map<String, Object> args = ImmutableMap.<String, Object>builder()
.put(ID_COL, modelId)
.put(ORG_ID_COL, orgId)
.put(NAME_COL, name)
.put(SCORES_TABLE_NAME_COL, scoresTableName)
.put(TARGET_TABLE_NAME_COL, targetTableName)
.put(ATTRIB_JSON_COL, attributes)
.build();
if (insert) {
insert().withTableName(TABLE).execute(args);
userModel.setId(modelId);
上面是DaoImpl。 TABLE 的值在 Dao 之上的层中声明为
public static final String TABLE = "user_models";
最佳答案
我们遇到了同样的错误。
我们的“tableName”是另一个架构中的表的同义词。
但是关于https://jira.spring.io/browse/SPR-4782 默认情况下,Oracle Connection 配置为“includeSynonyms”= false。
尝试这个来解决这个问题:
new SimpleJdbcInsert(datasource)
.includeSynonymsForTableColumnMetaData()
.withTableName("tableName");
此外,我们还有 pooledConnections,因此为了处理这个问题,我们必须指定 native jdbc 提取器:
new SimpleJdbcInsert(datasource)
.useNativeJdbcExtractorForNetaData(new OracleJdbc4NativeJdbcExtractor())
.includeSynonymsForTableColumnMetaData()
.withTableName("tableName");
关于java - SimpleJdbcInsert 无法定位表 'user_models' 的列,因此无法生成插入语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28026966/