-->
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.  [ 6 posts ] 
Author Message
 Post subject: How do I generate code from hbm.xml by hbm2net
PostPosted: Fri Dec 23, 2005 2:00 am 
Newbie

Joined: Tue Oct 28, 2003 3:03 am
Posts: 2
I try to run NHibernate.tool.hbm2net in nHibernateContrib.
I issue NHibernate.tool.hbm2net Employee.hbm.xml, but it seems generate nothing.

Does I miss any thing ?


the following is the log
log4net: XmlHierarchyConfigurator: Configuration update mode [Merge].
log4net: XmlHierarchyConfigurator: Logger [root] Level string is [INFO].
log4net: XmlHierarchyConfigurator: Logger [root] level set to [name="INFO",value
=40000].
log4net: XmlHierarchyConfigurator: Loading Appender [console] type: [log4net.App
ender.ConsoleAppender]
log4net: PatternParser: Converter [message] Option [] Format [min=-1,max=2147483
647,leftAlign=False]
log4net: PatternParser: Converter [newline] Option [] Format [min=-1,max=2147483
647,leftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [ConversionPattern] to Strin
g value [%d [%t] %-5p %c [%x] <%X{auth}> - %m%n]
log4net: PatternParser: Converter [d] Option [] Format [min=-1,max=2147483647,le
ftAlign=False]
log4net: PatternParser: Converter [literal] Option [ [] Format [min=-1,max=21474
83647,leftAlign=False]
log4net: PatternParser: Converter [t] Option [] Format [min=-1,max=2147483647,le
ftAlign=False]
log4net: PatternParser: Converter [literal] Option [] ] Format [min=-1,max=21474
83647,leftAlign=False]
log4net: PatternParser: Converter [p] Option [] Format [min=5,max=2147483647,lef
tAlign=True]
log4net: PatternParser: Converter [literal] Option [ ] Format [min=-1,max=214748
3647,leftAlign=False]
log4net: PatternParser: Converter [c] Option [] Format [min=-1,max=2147483647,le
ftAlign=False]
log4net: PatternParser: Converter [literal] Option [ [] Format [min=-1,max=21474
83647,leftAlign=False]
log4net: PatternParser: Converter [x] Option [] Format [min=-1,max=2147483647,le
ftAlign=False]
log4net: PatternParser: Converter [literal] Option [] <] Format [min=-1,max=2147
483647,leftAlign=False]
log4net: PatternParser: Converter [X] Option [auth] Format [min=-1,max=214748364
7,leftAlign=False]
log4net: PatternParser: Converter [literal] Option [> - ] Format [min=-1,max=214
7483647,leftAlign=False]
log4net: PatternParser: Converter [m] Option [] Format [min=-1,max=2147483647,le
ftAlign=False]
log4net: XmlHierarchyConfigurator: Setting Property [Layout] to object [log4net.
Layout.PatternLayout]
log4net: XmlHierarchyConfigurator: Created Appender [console]
log4net: XmlHierarchyConfigurator: Adding appender named [console] to logger [ro
ot].
log4net: XmlHierarchyConfigurator: Retrieving an instance of log4net.Repository.
Logger for logger [NHibernate.Tool].
log4net: XmlHierarchyConfigurator: Setting [NHibernate.Tool] additivity to [Fals
e].
log4net: XmlHierarchyConfigurator: Logger [NHibernate.Tool] Level string is [DEB
UG].
log4net: XmlHierarchyConfigurator: Logger [NHibernate.Tool] level set to [name="
DEBUG",value=30000].
log4net: XmlHierarchyConfigurator: Adding appender named [console] to logger [NH
ibernate.Tool].
log4net: XmlHierarchyConfigurator: Hierarchy Threshold []
2005-12-23 13:59:16,739 [3924] INFO NHibernate.Tool.hbm2net.CodeGenerator [(nul
l)] <(null)> - Employee.hbm.xml
2005-12-23 13:59:16,779 [3924] INFO NHibernate.Tool.hbm2net.Generator [(null)]
<(null)> - Generating 0 in generated
2005-12-23 13:59:16,789 [3924] INFO NHibernate.Tool.hbm2net.VelocityRenderer [(
null)] <(null)> - No template file was specified, using default
log4net: Hierarchy: Shutdown called on Hierarchy [log4net-default-repository]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 3:51 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
Could you please post your code?

What I've done in my code is use NHibernate.Mapping.Attributes to declare my schema, and then build the .hbn.xml file from that. Once built, I update it in the project and *rebuild* (this is important -- embedded resources will not be updated unless the project is rebuilt).

Note that I pass in a coupe of extra parameters in the settings (e.g., the Assembly to be processed) because this code is from a library I reuse in different projects.

Code:
public static void ParseFromAttributes( IDictionary settings )
{
   Assembly assembly = (Assembly) settings["Assembly"];
   string directory = (string) settings["Directory"];
   Configuration cfg = CreateConfiguration( settings );
   System.IO.MemoryStream stream = new System.IO.MemoryStream(); // Where the information will be written in

   // Gather information from this assembly (can also be done class by class)
   HbmSerializer.Default.Serialize( stream, assembly );
   
   // this will create the .hbm.xml file in the specified directory
   string filename = string.Format( "{0}\\{1}.hbm.xml", directory, assembly.GetName().Name );
   StreamWriter fileStream = new StreamWriter( filename, false, System.Text.Encoding.UTF8 );
   stream.Position = 0;
   StreamReader r = new StreamReader( stream );
   fileStream.WriteLine( r.ReadToEnd() );
   fileStream.Close();

   // Now create the schema and build the tables
   stream.Position = 0;
   try
   {
      cfg.AddInputStream(stream);
      new NHibernate.Tool.hbm2ddl.SchemaExport(cfg).Create(true, true);
   }
   finally
   {
      stream.Close();
   }
}

internal static Configuration CreateConfiguration(IDictionary settings)
{
   string connectionProvider = (string) settings["ConnectionProvider"];
   if (connectionProvider == null)
      connectionProvider = "NHibernate.Connection.DriverConnectionProvider";
   string dialect = (string) settings["Dialect"];
   if (dialect == null)
      dialect = "NHibernate.Dialect.MsSql2000Dialect";
   string driver = (string) settings["ConnectionDriver"];
   if (driver == null)
      driver = "NHibernate.Driver.SqlClientDriver";
   string schema = (string) settings["DBSchema"];
   if (schema == null)
      schema = "dbo";

   string connectionString = (string) settings["ConnectionString"];

   Configuration cfg = null;
   try
   {
      cfg = new Configuration();
      cfg.SetProperty( NHibernate.Cfg.Environment.ConnectionProvider,   connectionProvider );
      cfg.SetProperty( NHibernate.Cfg.Environment.Dialect,         dialect);
      cfg.SetProperty( NHibernate.Cfg.Environment.ConnectionDriver,   driver);
      cfg.SetProperty( NHibernate.Cfg.Environment.ConnectionString,   connectionString );
      cfg.SetProperty( NHibernate.Cfg.Environment.DefaultSchema,      schema );
   }
   catch( Exception ex )
   {
      Utility.ErrorHandling.DumpException( ex );
      throw;
   }
   return cfg;
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 4:48 pm 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
Perhaps I misunderstood your request in my earlier response. Do you want to generate C# code from an .hbm.xml file? Typically, you either create the .hbm.xml file manually or generate it from your code using NHibernate.Mapping.Attributes.

Gene


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 24, 2005 4:53 am 
Newbie

Joined: Tue Oct 28, 2003 3:03 am
Posts: 2
Thanks for your answer.
What I exactly want is how to generate c-sharp code from hbm.xml by hbm2net.

I try to run hbm2net someFile.hbm.xml, but it generate nothing, did I miss anything or what is the workaround ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 11:35 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
You might look at the code for the hbm2net NAnt task, also in NHibernateContrib. It calls hbm2net.exe. We used to use this (I wrote the task) but that was two years ago.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 6:47 pm 
Newbie

Joined: Mon Dec 12, 2005 4:11 am
Posts: 6
I'm working through the source for hbm2net and on my machine the hbm2net task is broken. Basically NVelocity coughs running under nant which obviously gives hbm2net problems as nvelocity is the default renderer. If anyone is sucessfully running the hbm2net task I'd like to figure out how my environment differs from yours.


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