JPA DB2 - 删除表后获取SQLCODE“-204”,SQLSTATE“42704”和SQLCODE = -727,SQLSTATE = 56098

时间:2015-11-10 18:43:46

标签: jpa db2

我的桌子掉了之后,我遇到了一个令人烦恼的问题。

我正在尝试保留一个实体,但每次我调用persist(...)时都会收到此错误消息:

引起:com.ibm.db2.jcc.am.SqlException:在隐式操作“3”期间发生错误。 SQLCODE“-204”,SQLSTATE“42704”和来自消息“MYDB2SCHEMA.TB_ABCD”的标记.. SQLCODE = -727,SQLSTATE = 56098,DRIVER = 4.12.56

看起来它无法找到“MYDB2SCHEMA.TB_ABCD”,当然它不会像上周DBA掉线一样。但这很奇怪,因为我试图坚持的实体与“MYDB2SCHEMA.TB_ABCD”实体没有任何关系,我们称之为ABCDEntity。

为了让事情变得更复杂,我删除了ABCDEntity,以便不再有与之相关的实体,然后我在整个项目中搜索“MYDB2SCHEMA.TB_ABCD”并且没有任何内容,但我仍然得到了同样的错误。

我试图在DB2中持久存在的表与死表没有任何关系,我不是DBA,但我相信如果死表有任何关系,它会在删除期间删除。

那么,如果没有与之相关的实体/表,DB2或JPA为什么还在尝试查找该表呢?

1 个答案:

答案 0 :(得分:0)

数据库中必须有一些其他对象,例如触发器或视图,它们引用了被删除的表。 DB2尝试在引用该对象时重新验证该对象。如果跟踪持久性框架生成的确切SQL语句,您可能会更好地了解发生了什么。

如果由于某种原因你不能让你的DB2找出有问题的对象,你可以尝试这个查询来找到其他对象仍然依赖于缺失的表:

with t(s,n) as (values ('YOURSCHEMA','YOURTABLE'))
select 'control'    as object_type, 
       dschema      as schema, 
       dname        as name, 
       case dtype when 'y' then 'row permission' when '2' then 'column mask' else 'unknown' end as depend_type
from syscat.controldep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'datatype'   as object_type, 
       typeschema   as schema, 
       typename     as name, 
       case when typemodulename is not null then 'in module '|| typemodulename else '' end as depend_type
from syscat.datatypedep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'index'      as object_type, 
       indschema    as schema, 
       indname      as name, 
       ''           as depend_type
from syscat.indexdep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'package'    as object_type, 
       pkgschema    as schema, 
       pkgname      as name, 
       ''           as depend_type
from syscat.packagedep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'routine'    as object_type, 
       routineschema    as schema, 
       specificname     as name, 
       case when routinemodulename is not null then 'in module '|| routinemodulename else '' end as depend_type
from syscat.routinedep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'table-ish'  as object_type, 
       tabschema    as schema, 
       tabname      as name, 
       case dtype when 'S' then 'MQT'
                  when 'T' then 'staging table'
                  when 'V' then 'view'
                  when '7' then 'synopsis table'
                  else dtype end as depend_type
from syscat.tabdep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'trigger'    as object_type, 
       trigschema   as schema, 
       trigname     as name, 
       ''           as depend_type
from syscat.trigdep join t on btype = 'T' and (bschema,bname) = (s,n)
union all
select 'global var'     as object_type, 
       varschema        as schema, 
       varname          as name, 
       case when varmodulename is not null then 'in module '|| varmodulename else '' end as depend_type
from syscat.variabledep join t on btype = 'T' and (bschema,bname) = (s,n)