-->
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: Using the NHibernate.Mapping.Attributes
PostPosted: Thu Oct 19, 2006 10:42 pm 
Newbie

Joined: Thu Oct 19, 2006 10:29 pm
Posts: 2
Hi. I´m trying to use the NHibernate.Mapping.Attributes in order to auto generate the hbm.xml files instead of writing them by hand. By reading the examples I understand that I need to tell nHibernate to do it after I decorate the classes/properties. My HibernateHttpModule which was taken by this tutorial: http://www.theserverside.net/tt/article ... NHibernate.

The solution is designed with the 3tiers and the DAL are accessed through the use of a Facade Pattern, meaning that the classes that should be dynamically mapped are in the BOL tier and the HibernateHttpModule is in the DAL tier, so if I use the following code in the HibernateHttpModule.cs :

Code:
         // Use NHibernate.Mapping.Attributes to create information about our entities
         System.IO.MemoryStream stream = new System.IO.MemoryStream(); // Where the information will be written in
         NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
         // Ask to NHibernate to use fields instead of properties
         NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";
         // Gather information from this assembly (can also be done class by class)
         NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetExecutingAssembly() );
         stream.Position = 0;
         config.AddInputStream( stream ); // Send the Mapping information to NHibernate Configuration
         stream.Close();


Then System.Reflection.Assembly.GetExecutingAssembly() will refer to the ExecutingAssembly which is DAL, thus there will be NO classes to map since they are in the BOL assembly ... should I map the classes 1 by 1, like:

Code:
System.IO.MemoryStream stream = new System.IO.MemoryStream(); // Where the information will be written in
         NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)
         // Ask to NHibernate to use fields instead of properties
         NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";
         // Gather information from this assembly (can also be done class by class)
         NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetAssembly( typeof( BOL.Class1) ) );
         stream.Position = 0;
         NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize( stream, System.Reflection.Assembly.GetAssembly( typeof( BOL.Class2) ) );
         stream.Position = 0;
         oConfig.AddInputStream( stream ); // Send the Mapping information to NHibernate Configuration
         stream.Close();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 2:40 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
You can use
typeof(BOL.Class1).Assembly instead of
System.Reflection.Assembly.GetAssembly( typeof( BOL.Class1) )

And, if BOL.Class2 and BOL.Class1 are in one assembly, there is not much point to add that assembly twice.

(i.e
typeof( BOL.Class1).Assembly == typeof( BOL.Class2).Assembly
)
Gert

_________________
If a reply helps You, rate it!


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.