oracle org.hibernate.tool.schema.spi.CommandAcceptanceException:无法执行命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36868709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:13:38  来源:igfitidea点击:

org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command

javaoraclehibernate

提问by yashpal bharadwaj

I am new to hibernate and trying to map an already created Table in oracle db. in Below given code:

我是 hibernate 的新手,并试图在 oracle db 中映射一个已经创建的表。在下面给出的代码中:

Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();

String hql = "FROM CrbtSubMasterDemo where rownum<20";
Query query = session.createQuery(hql);

List itr = query.list();
session.getTransaction().commit();

for (Iterator iterator = itr.iterator(); iterator.hasNext();)
{
System.out.println("[" + iterator.next() + "]");
}

When I run this code. It First gives this Exception:

当我运行此代码时。它首先给出了这个例外:


Apr 26, 2016 8:10:47 PM org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl processGetTableResults
INFO: HHH000262: Table not found: sdp.crbt_subscriber_master
Hibernate: create table sdp.crbt_subscriber_master (MSISDN varchar2(255) not null, STATUS varchar2(255), DATE_REGISTERED date, PLAN_INDICATOR number(10,0), RBT_CODE number(10,0), PASSWORD varchar2(255), TPIN varchar2(255), FREE_EVENTS_USED number(10,0), BLACK_LISTED number(10,0), LANGUAGE number(10,0), DEFAULT_GROUP_SETTING varchar2(255), DEFAULT_SINGLE_SETTING varchar2(255), DATE_SETTING_VALIDITY number(10,0), IMSI varchar2(255), LAST_CHARGED date, IS_MONTHLY_CHARGEABLE varchar2(255), CORP_ID number(10,0), SUB_TYPE varchar2(255), RENEW_MODE number(10,0), EXPIRY_DATE date, ACTIVE_FEATURES number(10,0), IN_USE_RBT number(10,0), UPDATE_TIME date, CORP_EXPIRY date, primary key (MSISDN))
Apr 26, 2016 8:10:47 PM org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl handleException
WARN: GenerationTarget encountered exception accepting command : Unable to execute command [create table sdp.crbt_subscriber_master (MSISDN varchar2(255) not null, STATUS varchar2(255), DATE_REGISTERED date, PLAN_INDICATOR number(10,0), RBT_CODE number(10,0), PASSWORD varchar2(255), TPIN varchar2(255), FREE_EVENTS_USED number(10,0), BLACK_LISTED number(10,0), LANGUAGE number(10,0), DEFAULT_GROUP_SETTING varchar2(255), DEFAULT_SINGLE_SETTING varchar2(255), DATE_SETTING_VALIDITY number(10,0), IMSI varchar2(255), LAST_CHARGED date, IS_MONTHLY_CHARGEABLE varchar2(255), CORP_ID number(10,0), SUB_TYPE varchar2(255), RENEW_MODE number(10,0), EXPIRY_DATE date, ACTIVE_FEATURES number(10,0), IN_USE_RBT number(10,0), UPDATE_TIME date, CORP_EXPIRY date, primary key (MSISDN))]
org.hibernate.tool.schema.spi.CommandAcceptanceException: Unable to execute command [create table sdp.crbt_subscriber_master (MSISDN varchar2(255) not null, STATUS varchar2(255), DATE_REGISTERED date, PLAN_INDICATOR number(10,0), RBT_CODE number(10,0), PASSWORD varchar2(255), TPIN varchar2(255), FREE_EVENTS_USED number(10,0), BLACK_LISTED number(10,0), LANGUAGE number(10,0), DEFAULT_GROUP_SETTING varchar2(255), DEFAULT_SINGLE_SETTING varchar2(255), DATE_SETTING_VALIDITY number(10,0), IMSI varchar2(255), LAST_CHARGED date, IS_MONTHLY_CHARGEABLE varchar2(255), CORP_ID number(10,0), SUB_TYPE varchar2(255), RENEW_MODE number(10,0), EXPIRY_DATE date, ACTIVE_FEATURES number(10,0), IN_USE_RBT number(10,0), UPDATE_TIME date, CORP_EXPIRY date, primary key (MSISDN))]
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:63)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:567)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:551)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.createTable(SchemaMigratorImpl.java:339)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.performMigration(SchemaMigratorImpl.java:257)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:137)
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:110)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:176)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:64)
    at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:458)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:465)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
    at com.telemune.demoHibernate.QueryTester.(QueryTester.java:17)
    at com.telemune.demoHibernate.QueryTester.main(QueryTester.java:21)
Caused by: java.sql.SQLException: ORA-00955: name is already used by an existing object

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
    at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:210)
    at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:961)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1190)
    at oracle.jdbc.driver.OracleStatement.executeInternal(OracleStatement.java:1726)
    at oracle.jdbc.driver.OracleStatement.execute(OracleStatement.java:1696)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:51)
    ... 14 more

Apr 26, 2016 8:10:47 PM org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl processGetTableResults
INFO: HHH000262: Table not found: sdp.crbt_subscriber_master
Apr 26, 2016 8:10:47 PM org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl processGetTableResults
INFO: HHH000262: Table not found: sdp.crbt_subscriber_master

and then show the required result successfully. But I want to know the reason for the Exception. Asking for help. I only know some things about hibenate, sorry if its a silly question.

sdpis the name of data base. and this is my mapping:

and then show the required result successfully. But I want to know the reason for the Exception. Asking for help. I only know some things about hibenate, sorry if its a silly question.

sdpis the name of data base. and this is my mapping:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">; 
<hibernate-mapping> 
<class name="com.telemune.demoPojo.CrbtSubMasterDemo" 
table="sdp.crbt_subscriber_master"> 
<id column="MSISDN" name="mobile" type="java.lang.String">
<generator class="native"/></id> 
</hibernate-mapping>

采纳答案by v.ladynev

I think the problem is that you specify a schema name with a table name here

我认为问题是你在这里指定了一个带有表名的模式名

<class name="com.telemune.demoPojo.CrbtSubMasterDemo" 
  table="sdp.crbt_subscriber_master">

Hibernate considers sdp.crbt_subscriber_masteras a table name.

Hibernate 将其sdp.crbt_subscriber_master视为表名。

But when Hibernate tries to execute create table sdp.crbt_subscriber_master()Oracle considers sdpas a schema name and crbt_subscriber_masteras a table name.

但是当 Hibernate 尝试执行时,create table sdp.crbt_subscriber_master()Oracle 将其sdp视为模式名称和crbt_subscriber_master表名称。

Don't know exactly how to specify a schema name for a mapping but you can try as described here

不知道如何为映射指定架构名称,但您可以按照此处所述进行尝试

Chapter 5. Basic O/R Mapping: mapping-declaration-class

第 5 章 基本 O/R 映射:mapping-declaration-class

<class name="com.telemune.demoPojo.CrbtSubMasterDemo" 
  schema="sdp" table="crbt_subscriber_master">

回答by SkyWalker

Here table name is case sensitive. There is a mismatch.

这里表名区分大小写。存在不匹配。

INFO: HHH000262: Table not found: sdp.crbt_subscriber_master

Database is trying to get crbt_subscriber_masterbut you have given

数据库正在尝试获取crbt_subscriber_master但您已给出

String hql = "FROM CrbtSubMasterDemo where rownum


Your issue is here:

你的问题在这里:

There is another problem also. You have missed to add declaring hql perfectly.

还有另一个问题。您错过了完美地添加声明 hql。

Use this code

使用此代码

String hql = "FROM CrbtSubMasterDemo where rownum";

instead of

代替

String hql = "FROM CrbtSubMasterDemo where rownum

You can also go through this tutorial: ORA-00955: name is already being used by existing object tips

您还可以阅读本教程:ORA-00955: name is already being used by existing object tips



UPDATE:

更新:

hibernate.hbm2ddl.auto Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.

e.g. validate | update | create | create-drop

hibernate.hbm2ddl.auto 在创建 SessionFactory 时自动验证或导出模式 DDL 到数据库。使用 create-drop,当 SessionFactory 显式关闭时,数据库模式将被删除。

例如验证| 更新 | 创建 | 创建删除

So the list of possible options are,

所以可能的选项列表是,

validate: validate the schema, makes no changes to the database.

validate:验证架构,不对数据库进行任何更改。

update: update the schema.

更新:更新架构。

create: creates the schema, destroying previous data.

create:创建模式,销毁以前的数据。

create-drop: drop the schema at the end of the session.

create-drop:在会话结束时删除架构。

So, As it is already created the data table. Then if you remove this property from your configuration, then it will be solved.

所以,因为它已经创建了数据表。然后如果你从你的配置中删除这个属性,那么它就会解决。

<property name="hbm2ddl.auto">update</property>

But you can give a try. This will also solve the issue.

但是你可以试一试。这也将解决问题。

<property name="hbm2ddl.auto">validate</property>

or

或者

<property name="hbm2ddl.auto">none</property>

Sometimes empty string' is much more better than 'none'. To use 'none', you will receive warning message: org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none

有时空字符串'比'无'好得多。要使用“无”,您将收到warning message: org.hibernate.cfg.SettingsFactory - Unrecognized value for "hibernate.hbm2ddl.auto": none