-->
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.  [ 3 posts ] 
Author Message
 Post subject: Create database tables from NHibernate
PostPosted: Tue Oct 24, 2006 9:37 am 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
I've been looking at the docs, but it seems like you have to use java-tools to create schemata. I've also tried searching this forum, but couldn't find a post dealing with this.

I'm writing a blog and would like to do this (Pseudo-code):
Code:
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();

Blog blog = new Blog();
blog.Name = "My Own Blog";
blog.TablePrefix = "blog_";
...
blog.AnotherProperty = "this and that";
session.Save( blog );
   
try {
    //creates a couple of new tables based on the prefix - how do I make it create these tables?
    //Perhaps I could write the mapping xml files and somehow make them give the meta data needed to create this new blog in the database?
    tx.Commit();
}
catch {
    trans.Rollback();
}
finally {
    NHibernateHelper.CloseSession();
}


Hence, my question is; How do I make NHibernate create the tables for me? Either being able to create tables with customized naming, or create tables after the mapping files?

Hibernate version:
1.2.x.x

Mapping documents:
Entry, IPerson, Category, Comment, MembershipUser, Profile etc...

Name and version of the database you are using:
MySQL, but it should just be a setting in the web.config.


Top
 Profile  
 
 Post subject: sample with create schema
PostPosted: Tue Oct 24, 2006 10:21 am 
Newbie

Joined: Fri May 26, 2006 3:05 pm
Posts: 4
You might want to check out the following blog post by Benjamin Day.

http://blog.benday.com/archive/2005/10/25/3054.aspx

-k


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 1:31 pm 
Beginner
Beginner

Joined: Thu Oct 19, 2006 1:03 pm
Posts: 29
Good link... He's got it set up pretty good.

About the schema exporter: I got this far:
Code:
namespace Com.Benday.BugTracker.DataAccess
{
    public class SchemaUtility
    {
        public static void ExportSchema()
        {
            Configuration config = new Configuration();
            config.Configure();

            SchemaExport exporter = new SchemaExport(config);

            exporter.Drop(true, true);
            exporter.Create(true, true);
           
            // exporter.Execute(true, true, false, true);
        }
    }
}


And that's as far as I get... I've tried it out and it works great. One thing I found, was that using his older NHibernate.dll file, I get description in Visual Studio 2005 for every method, while the newer, nor 1.0.2 gives me descriptions.

Other than that, thanks, it helped me!


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