-->
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.  [ 4 posts ] 
Author Message
 Post subject: Automatically creation of tables from mapping files
PostPosted: Thu Oct 19, 2006 11:20 am 
Newbie

Joined: Thu Jun 08, 2006 4:08 am
Posts: 8
Hi!

Im using NHibernate 1.0 and want to ask if its possible to automatically create tables from the hbm.xml mapping files when running the application for the first time ( or if the tables are not present at runtime ). I know that this is possible with Hibernate, but i get exception with NHibernate if I try to persist something and tables doesn't exists.

Regards
Ismar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 1:09 pm 
Newbie

Joined: Wed Sep 06, 2006 8:33 am
Posts: 19
Hi, use this code before you call BuildSessionFactory():

Code:
SchemaExport meta = new SchemaExport(cfg);
meta.SetDelimiter(";");
meta.SetOutputFile("C:/schema.sql");
meta.Execute(true, false, false, false);


note: cfg is your Configuration cfg = new Configuration();

This code create a c:\schema.sql to create your database.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 1:20 pm 
Newbie

Joined: Thu Jun 08, 2006 4:08 am
Posts: 8
Tnx!
It worked to generate sql script for tables, but is it possible that generating and executing of this file can be done in the background. Its possible with ant or maven, but with just using NHibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 4:40 pm 
Beginner
Beginner

Joined: Fri Jul 22, 2005 4:08 pm
Posts: 28
Code:
SchemaExport se = new SchemaExport(Configuration);
se.Create(false, true);


First parameter to Create() is to dump the creation script to a file, second is to execute it directly (I believe?)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.