-->
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: NHibernate.Mapping.Attributes and auto-import=false
PostPosted: Thu Nov 15, 2007 7:13 am 
Newbie

Joined: Thu Nov 15, 2007 6:54 am
Posts: 2
Hello,

I'm trying to convert our solutions from using mapping files to using code attributes with NHibernate.Mapping.Attributes.

We have some objects which have the same name but in 2 different namespaces. When using mapping files, we would add auto-import=false onto the second mapping file on the "hibernate-mapping" element to avoid a "duplicate import" error. We had a hibernate-mapping element on each mapping file (one per class).

When using NHibernate.Mapping.Attributes, although I am decorating each class with a HibernateMapping attribute, there is only one hibernate-mapping element which is the root node after serialization.

Is there any way to solve this problem without renaming classes?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 1:09 pm 
Newbie

Joined: Thu Nov 15, 2007 6:54 am
Posts: 2
If anyone else has this problem, the trick is to decorate your classes with the
HibernateMapping attribute and serialize each class individually using the HbmSerializer like so :

Code:
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
Assembly a = Assembly.GetExecutingAssembly();
foreach (Type t in a.GetTypes())
{
   if (t.IsSubclassOf(typeof(YourBaseClass)))
   {
      System.IO.MemoryStream stream = new System.IO.MemoryStream();
               
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(stream, t);
      stream.Position = 0;
      cfg.AddInputStream(stream);
               
               
      stream.Close();
   }
}


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.