yashpal bharadwaj
yashpal bharadwaj

Reputation: 323

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

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

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.

sdp is 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>

Upvotes: 3

Views: 21502

Answers (2)

SkyWalker
SkyWalker

Reputation: 29150

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_master but you have given

String hql = "FROM CrbtSubMasterDemo where rownum

Your issue is here:

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

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


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

So the list of possible options are,

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

update: update the schema.

create: creates the schema, destroying previous data.

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

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

Upvotes: 0

v.ladynev
v.ladynev

Reputation: 19956

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_master as a table name.

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

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

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

Upvotes: 1

Related Questions