-->
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: Re: NHibernateEg.Tutorial1A released!
PostPosted: Sat Nov 19, 2005 3:19 am 
Newbie

Joined: Wed Nov 16, 2005 2:40 pm
Posts: 19
Location: Palo Alto, CA
I have gone through the tutorial, and have implemented attributes in my code. In one place, it struck me odd that I had to add attributes to the properties of the class, rather than to the class itself. For example:

Code:
[NHibernate.Mapping.Attributes.JoinedSubclass(NameType=typeof(Subclass), ExtendsType=typeof(SomeClass), Table="MyTable", Lazy=true)]
public class Subclass: SomeClass
{
   [NHibernate.Mapping.Attributes.Key(-1, Column="key" )]
   private string prop;
   [Nhibernate.Mapping.Attributes.Property]
   public string Prop
   {
      get { return prop; }
      set { prop = value; }
   }
}


It seems like Key should be specified right after JoinedSubclass, rather than inside the class. Also, I was wondering why the JoinedSubclass does not get emitted into the XML as a child of the appropriate class element, but rather as a sibbling, with the (as a result) required "extends" attribute.

Thanks for the neat tools!

Gene


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 19, 2005 9:56 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate.Mapping.Attributes behavior is hevily influenced by the XML representation of the mapping.

[Key] is a property/field attribute because <key> is a sub-element of <joined-subclass>.
This design was choosed because it allowed me to write a generator which means that all mapping are available and the maintenance cost is very low.

And the JoinedSubclass will be in its Class parent mapping only if you put it in the class body. Eg:
Code:
[Class] class BaseClass
{
    [JoinedSubclass] class ChildClass
    {}
}


Note that NHibernate.Mapping.Attributes doesn't try to be too smart: Here, ChildClass will be in BaseClass mapping and as "Extends" is not set, NHibernate will assume that ChildClass inherits from BaseClass...

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


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.