schema does not exist - Apache derby

How do i set the default schema "APP" to the user name "sa"?, How to do it with Hibernate?

My hibernate config xml file is here
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/AutoDB;</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">hidepassword</property>
<!-- Specific the default schema to connect  -->
<property name="hibernate.default_schema">APP</property>
<!-- Specific the default schema to connect  -->
<property name="hibernate.default_catalog">APP</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">300</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache  -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">false</property>
<!-- Drop and re-create the database schema on startup -->
<property name="">update</property>

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sathish David Kumar NArchitectCommented:
when you defind the sessionFactory property that time you can specify the  default_shema then it will apply all calss mapping files !!
ManikandanBalachandranAuthor Commented:
Yes i did that but still getting the same error "schema does not exist". Looks like default_schema is ment for Oracle or some other DBs not for Derby, Any other solutions please?
Sathish David Kumar NArchitectCommented:
r u using hbm file ??

yes means set shema there ! and remove from your xml file and check ??
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ManikandanBalachandranAuthor Commented:
Please give a sample hbm file for setting schema
If a database is created in Derby using the embedded driver and no user name is specified, the default schema used becomes APP. Therefore any tables created in the database have a schema name of APP. However, when creating a Derby database using the Network Server, the value for the schema becomes the value of the username used to connect with as part of the database URL.

This is an inherant limitation with derby and you cannot specify the default schema. There are 2 options that you can use
1. Always prepend schema name to table name (for example APP.table1  instead of table1)
2. Use the derby embedded driver to run derby in embedded mode; but remember that in embedded mode data CANNOT be accessed (and manipulated) with third party tools. To do this, change the driver to

<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
<property name="hibernate.connection.url">jdbc:derby:AutoDB;</property>

For details on derby embedded mode, check out

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sathish David Kumar NArchitectCommented:
<class name="com.tts.papa.javabeans.DocApprovalDetails" table="DOC_APPROVAL_DETAILS" shema ="check">
@dravidnsr, with derby there is no notion of a schema that you can specify in a HBM file. The driver will always connect to the default schema only as per derby.
Sathish David Kumar NArchitectCommented:
Is it ...  I didnt work in derby . i thought its apacy product so we can use hbm ...

Thanks ...
The current schema for any connection defaults to a schema corresponding to the user name. If no user name is supplied then the user name (and hence current schema) defaults to APP.

However even though the current schema is set to the user name, that schema may not exist. A schema is only created by CREATE SCHEMA or creating an object (table etc.) in that schema (this is implicit schema creation).

The one exception to this is the APP schema, which is always created, though applications should not depend on that.

So you will see the schema not exists error if your application tries to access the current schema before any objects have been created in it. Possibilities are you try to perform a DROP TABLE before creating it, or try to SELECT from a table to see if it should be created or not, or when there is a problem with the sql for the very first object you try to create in a particular schema and no explicit CREATE SCHEMA was issued.
Kevin CrossChief Technology OfficerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.