有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Spring hibernate:无法提取结果集元数据

我尝试在我的Dao中使用本机查询(从JpaRepository扩展而来),但我遇到了以下异常:

org.springframework.orm.jpa.JpaSystemException: Could not extract result set metadata; nested exception is org.hibernate.HibernateException: Could not extract result set metadata

这是我的本机查询:

@Repository
public interface BenchDao extends JpaRepository<Bench, Long> {


@Query(nativeQuery=true,value="UPDATE TF_BENCH SET ISDELETED = 1, SEQ = (select CASE WHEN (min(BENCH.SEQ) < 1) THEN (min(BENCH.SEQ)-1) ELSE -1 END from TF_BENCH BENCH WHERE BENCH.STAGE = (select BENCH.STAGE from TF_BENCH BENCH WHERE id =29302)) WHERE id =29302")
void deleteBench();

当我在OracleSQLDeveloper上尝试这个请求时,它可以工作,但通过spring和hibernate它不能工作

在堆栈跟踪执行中,我还有以下消息:

Caused by: java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement

我试着用谷歌搜索异常消息,但什么也没找到


共 (2) 个答案

  1. # 1 楼答案

    我找到了一个解决方案:如果有人需要:

    @Repository
    public class BenchDaoCustomImpl implements BenchDaoCustom {
    
        @PersistenceContext
        private EntityManager em;
    
        public void deleteBench(Long benchId) {
            this.em.createNativeQuery("UPDATE TF_BENCH SET ISDELETED = 1, SEQ = (select CASE WHEN (min(BENCH.SEQ) < 1) THEN (min(BENCH.SEQ)-1) ELSE -1 END from TF_BENCH BENCH WHERE BENCH.STAGE = (select BENCH.STAGE from TF_BENCH BENCH WHERE id =?0)) WHERE id =?0")
                .setParameter(0, benchId)
                .executeUpdate();
        }
    }