Issue Details (XML | Word | Printable)

Key: HHH-1853
Type: Improvement Improvement
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Mattias Jiderhamn
Votes: 17
Watchers: 19
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

CREATE SCHEMA inside database-object need to execute before tables are created

Created: 26/Jun/06 08:41 AM   Updated: 06/Nov/09 03:10 PM
Component/s: None
Affects Version/s: 3.1.3
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments: 1. Text File create-schema.patch (4 kB)
2. Text File create-schema2.patch (5 kB)

Environment: hsqldb 1.8.0
Issue Links:
Duplicate
 

Participants: Ed Gow, Grigoras Cristinel, Johnathan James, Kalle Korhonen, Limbicsystem, Mattias Jiderhamn, Max Rydahl Andersen, Stephen Cooper and tom quas


 Description  « Hide

In order to have Hibernate create database schemas for hsqldb, you have to insert a <database-object> in your mapping file (http://forums.hibernate.org/viewtopic.php?p=2305138). Problem is, all the database-object statements are executed after the tables are created, so tables in non-default schemas will not be created. To get around this, you have to first use Configuration.generateSchemaCreationScript() to get the schemas, and then Configuration.generateSchemaUpdateScript() to get the tables inside the schemas.

(This is a bit problematic when using Springs LocalSessionFactoryBean)



Grigoras Cristinel added a comment - 28/Jun/06 06:03 AM

Hi,

PostgresSQL will not create the schema.
How can i fix that ?

Cristi


Mattias Jiderhamn added a comment - 28/Jun/06 06:09 AM

Click the link to the forum, and post your question there.
JIRA is for bug/issue tracking, not support.


Mattias Jiderhamn added a comment - 22/Nov/06 05:50 AM

As of Hibernate 3.2.1 the workaround mentioned above does no longer work, since a call to buildSettings() is introduced in org.hibernate.cfg.Configuration.generateSchemaUpdateScript(). Since settings have already been build, Spring will throw "No local DataSource found for configuration - dataSource property must be set on LocalSessionFactoryBean" from its LocalDataSourceConnectionProvider.

Suddenly this moves from being a "Minor" problem to a "Major", since we cannot run our tests with 3.2.1.


tom quas added a comment - 15/Feb/07 10:09 AM

I prepared a patch against the 3.2 branch that solves this problem for our environment, namely H2, PostgreSQL, and SQL Server 2005. Note that I could not make it work with Hypersonic/HSQL since its CREATE SCHEMA statement requires a mandatory AUTHORIZATION part that I didn't want to deal with at this point. Somebody else might know how to fix this problem in an efficient way. Anyway, H2 gave our test suite a tremendous boost, so dropping HSQL was the logical step and we're happy.

See attachment create-schema.patch


tom quas added a comment - 15/Feb/07 10:10 AM

patch to generate CREATE SCHEMA/DROP SCHEMA statements during DDL generation


Max Rydahl Andersen added a comment - 15/Feb/07 11:32 AM

so you want schemaexport to automatically create and drop schemas after its done......that's dangerous!


tom quas added a comment - 15/Feb/07 11:57 AM

Living on the edge... Seriously, that seems to be the quick/only way for us to make our tests run. Since we're maintaining our production schema manually we don't have a problem here.

Besides, since we drop the tables, what's so funny about dropping the schemas, too?


Max Rydahl Andersen added a comment - 15/Feb/07 12:03 PM

hibernate knows exactly which tables it created.......but it does not know if all tables in a schema has been removed. With a too liberal db/rights you would be nuking out things you shouldn't.


tom quas added a comment - 16/Feb/07 02:35 AM

Agreed. Is there a good way to lower the danger of accidentally doing this that's currently supported by Hibernate? I could consider this in the patch. If not, I'd vote for leaving that up to the developer/DBA and go with the simple solution.


Stephen Cooper added a comment - 25/Sep/07 01:50 PM

Modification of previous patch, so that the schema creation syntax is delegated to the dialect object.
Also, patched the HSQL dialect so that it generates the schema with the required "authorization dba" additional syntax.


Limbicsystem added a comment - 22/Oct/08 08:58 PM

Has this patch made it into a released version? I've tried applying it (the second attachment) to Hibernate 3.2.2 with strange results. When used in conjunction with H2 1.0.79, the schemas get created, but after the attempts to create the tables. This obviously doesn't work. With so many moving parts it's kind of hard to tell what's wrong. Pointers to a Hibernate release that works with H2 would be greatly appreciated.

Thanks


Ed Gow added a comment - 04/Jun/09 06:37 PM

The crux of the issue seems to be just the creation of schema, not dropping schema. Earlier comments about dropping more than is intended provide good reason for not dropping schema from Hibernate. Can a version of the patch for this bug that only creates, but never drops, schema make it into a release?

This bug is a serious impediment for the common case of using an H2 in-memory database for unit testing.


Kalle Korhonen added a comment - 08/Jun/09 03:28 PM

hbm2ddl.auto=update seems to work for me with h2 when use org.hibernate.dialect.H2Dialect rather than HSQLDialect


Johnathan James added a comment - 06/Nov/09 03:10 PM

This issue should be fixed.

All that is necessary is an option to force creation of the schemas if none are present. Users should not have to update and recompile code to make this happen.

Its been over three years at this point.