-->
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.  [ 10 posts ] 
Author Message
 Post subject: Generate Database From Attributes or XML
PostPosted: Wed Oct 12, 2005 4:57 am 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
I am new to nHibernate but I have been using an ORM that generated the database tables for me,,

Is there a tool that can generate the database tables and relations from the xml or the attributes ??

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 12, 2005 1:37 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Yes, SchemaExport:
Code:
NHibernate.Cfg.Configuration cfg = GetFullyConfigured(...);
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Create(true, true);

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Another Question
PostPosted: Wed Oct 12, 2005 3:30 pm 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
Thanks for the reply,

But is it possible to use that at runtime ?
That the user can specify the database connection details, then the database is generated and then used without having to restart the application to reload a configuration file ?

I am asking that because I will be using nHibernate in a desktop application , and the user might specify the connection settings, so i wanted to use these settings without asking him to change them in a config file or reload the application to reload that file ,,..

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 13, 2005 9:33 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Yes, it works at runtime.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: RE:Generate Database From Attributes or XML
PostPosted: Wed Oct 26, 2005 5:47 am 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
Hello again,
I have tried
Code:
NHibernate.Cfg.Configuration cfg = GetFullyConfigured(...);
new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Create(true, true);


on a sample i downloaded from [url=http://weblogs.asp.net/pwilson/archive/2005/05/26/409042.aspx] wilson sample
[/url]

its hbm.xml file contains many-to-many relation as the following [i trimmed some fields for simplicity]

Code:
<class name="Wilson.NHibernate.Example.Category, WilsonNHibernateExample" table="Categories">
      <id name="Id" column="CategoryId">
         <generator class="assigned" />
      </id>
      <bag name="Contacts" table="CategoryContacts" cascade="none" access="nosetter.camelcase" lazy="false" inverse="true">
         <key column="CategoryId" />
         <many-to-many column="ContactID" class="Wilson.NHibernate.Example.Contact, WilsonNHibernateExample" />
      </bag>
   </class>
   <class name="Wilson.NHibernate.Example.Contact, WilsonNHibernateExample" table="Contacts" discriminator-value="?" >
      <id name="Id" column="ContactId" access="nosetter.camelcase" unsaved-value="0">
         <generator class="identity" />
      </id>
      <bag name="Categories" table="CategoryContacts" cascade="none" access="nosetter.camelcase" lazy="false" inverse="false">
         <key column="ContactId" />
         <many-to-many column="CategoryId" class="Wilson.NHibernate.Example.Category, WilsonNHibernateExample" />
      </bag>
   </class>


This xml generates
Code:
create table CategoryContacts (
  CategoryId NVARCHAR(255) not null,
   ContactID INT null,
   ContactId INT not null
)


which causes an error clearly because of the duplicate column name.
This is caused that the column is generated twice from both the decalaratins in the two classes ,,
how to overcome this error ?
or what am i missing ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 8:11 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
I think that if you correct the case of ContactID to ContactId everything will work as expected.


Top
 Profile  
 
 Post subject: RE:Generate Database From Attributes or XML
PostPosted: Thu Oct 27, 2005 3:10 am 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
OK ,, That hurts 8) ,, it did work

Thanks alot


Top
 Profile  
 
 Post subject: Generate Default mappings
PostPosted: Thu Oct 27, 2005 7:17 am 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
Is there a way to generate default mapping xml file ?
I need a tool to parse the code files (classes) generate a default mapping xml file , for native data types fields at least and then i ll handle relations between objects,

Is there a tool that do that without adding attributes to all fields ???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 27, 2005 8:47 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Without attributes, there is no way to give all the information required to build a mapping file... You might take all public properties and only set their name in the mapping, but it will not be time-saving in the long run.

Anyway, you can easily write a generator using reflection to do this job...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 30, 2005 3:58 am 
Newbie

Joined: Wed Oct 12, 2005 4:36 am
Posts: 9
I thought of writing my own parser but the reflection Idea is better :idea: ,

Thanks for your help


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