【发布时间】:2018-03-23 15:33:33
【问题描述】:
当尝试使用 JpaRepository 和 @Query 注释对表执行更新时,我收到错误“表不存在”并且:
has thrown exception:org.hibernate.exception.SQLGrammarException: could n
ot execute statement
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute s
tatement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException
: could not execute statement
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:261)
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:488)
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
Caused by: oracle.jdbc.OracleDatabaseException: ORA-00942: table or view does not exist
at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:498)
... 154 common frames omitted
我的查询:
@Modifying
@Transactional
@Query(nativeQuery = true, value = "UPDATE T_MY_TABLE SET VISIBLE_FLAG = 0 "
+ "WHERE ID = :myId ")
int updateMyTab(@Param("myId") Long myId);
使用JpaRepository.save方法更新表时,正常执行,没有任何问题。
另外,我有 SELECT nativeQueries,它可以工作。只有更新没有。
桌子上有: - 为模式创建同义词 - 授权选择、插入、更新、删除模式
表确实存在,如果直接在数据库和任何架构/用户上执行更新,它可以正常工作并更新行
【问题讨论】:
-
激活休眠查询日志并在此处发布生成的查询。
-
您是否尝试过在查询中指定架构,例如
UPDATE SCHEMA.T_MY_TABLE SET VISIBLE_FLAG = 0 -
@Maciej eM:你能解决这个问题吗?我也面临这个问题。
-
不幸的是,我不记得它最后是如何修复的。在此期间更改了 3 次项目,抱歉。
标签: spring oracle hibernate spring-data-jpa