-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Automatic create schema in database
PostPosted: Tue Jan 15, 2008 6:31 am 
Newbie

Joined: Tue Jan 15, 2008 6:26 am
Posts: 8
Hi,

is there any chance to let hiberrnate automatically create a schema?
I defined a default schema for my entities, but unfortunately it is only possible to deploy these entities, if the schema already exists in the database. I thought of something equal as it is already possible for automatic creation of database-tables for the entities if the property 'hibernate.hbm2ddl.auto' has been defined to 'create'.

Thanks for your help

Thomas

Hibernate version:
3.2.5 or newer

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 15, 2008 10:13 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
If you specify the default schema in the connection properties (hibernate.default_schema), Hibernate will write your data objects there. Additionally, you can specify a different schema on each of your mapping files (<hibernate-mapping. schema="xxx")

If what you want is to create several schemas on the fly, you can achieve that by creating several configuration objects.
Code:
      cfg.setProperty("hibernate.default_schema", "schema1");
String[] schema1=cfg.generateSchemaCreationScript(new org.hibernate.dialect.MckoiDialect());
      SchemaExport se1=new SchemaExport(cfg1);
      se1.create(true, true);

                ...

      cfg2.setProperty("hibernate.default_schema", "schema2");
String[] schema2=cfg.generateSchemaCreationScript(new org.hibernate.dialect.MckoiDialect());
      SchemaExport se2=new SchemaExport(cfg2);
      se2.create(true, true);



Consider, however, that your session comes from only one of those, therefore only one of these schemas can be takes as the default one. For the other, the schema will have to be specified in the schema name on the mapping files, or explicitly in your queries.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.