oracle建的创建建表的存储过程其中有外键约束, 在sqlplusw中调用没有问题,外键约束可以建出来,但是在java中调用创建的表就没有外键约束 ,报的错误:
ORA-00955: 名称已由现有对象使用
ORA-06512: 在 "SCOTT.BUILDDATA", line 19
ORA-06512: 在 line 1
数据库中没有这两个表,已经删掉后的。
先贴过程
CREATE OR REPLACE 
procedure builddata1 isv_comsql VARCHAR2(2000);
v_myusersql VARCHAR2(2000);
v_comcount number(30);
v_usercount number(30);begin
v_comsql:='
create table com(
com_name varchar2(20) not null unique,
com_order varchar2(20) primary key ,
bcom_order varchar2(20) not null unique,
com_ispare char(2) not null)';
v_myusersql:='create table myuser(
user_id char(32) primary key,
user_name varchar2(20) not null unique,
user_password varchar2(20) not null,
user_ispare char(2) not null,
branch_order varchar2(20) REFERENCES com(com_order)
)';select count(*) into v_comcount from user_tables where table_name='COM';
if v_comcount=0 then
  execute immediate v_comsql;
else
  dbms_output.put_line('com表存在');
end if;select count(*) into v_usercount from user_tables where table_name='MYUSER';if v_usercount=0 then
  execute immediate v_myusersql;
else
  dbms_output.put_line('myuser表存在');
end if;exception
when others then
dbms_output.put_line('创建表异常');
end builddata1;
再贴java代码:package com.manage.session;import org.hibernate.Query;
import org.hibernate.Session;
public class InstallDb {
private Session session;

public boolean installDb(){ boolean i=false;
try{
session=HibernateSessionFactory.getSession();
session.beginTransaction(); Query query=session.createSQLQuery("{call builddata()}");
query.executeUpdate(); 
session.getTransaction().commit();
i=true; }catch(Exception e){
session.getTransaction().rollback();
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return i;
}

}

解决方案 »

  1.   

    在scott用户下执行以下SQL看是否有该对象:SELECT * FROM tab;
      

  2.   

    会不会是其他的,不是table,查一下all_objects
      

  3.   

    SELECT * FROM tab; 这个查了tab表里没有那两个表名。
    all_objects 这个表没大看出来 ,里面也没有我要建的表啊。
    令这个是java程序执行的时候的错误,我在oracle中直接调用都没问题的....
    难道是tomcat缓存???那也不可能啊.....
      

  4.   

    如果方便的话,直接用jdbc试试,怀疑hibernate转换了
      

  5.   

    郁闷啊 用jdbc是可以的 没有问题....