-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to use <component> with NHibernate.Mapping.Attribu
PostPosted: Wed Aug 17, 2005 10:35 am 
Hi All,

Several of my classes (and tables) contain a validity information (beginDate and endDate fields of "dateTime" type).

I'm trying to implement a <component> containing this info and that could be reused in each class. I'm defining the mapping with mapping attributes in my classes.

As I'm quite a newbie on Nhibernate, my first question is : Is it the correct way to handle that kind of problems?

I'd like to get this kind of hbm file but through mapping attributes :
Code:
<component name="ValidityPeriod" class="ValidityPeriod">
    <property name="BeginDate" access="field" />
    <property name="EndDate" access="field" />
</component>


The [component] attribute is a class attribute, then I implemented by ValidityPeriod class like :
Code:
   [Component(Name="ValidityPeriod")]
   public class ValidityPeriod
   {
      private static DateTime INFINITE = new DateTime(9999,12,31);

      public DateTime _begin;
      public DateTime _end; // never null

      public DateTime Begin
      {
         get
         {
            return _begin;
         }
         set
         {
            _begin = value;
         }
      }

      public XsDateTime End
      {
         get
         {
            if (_end == INFINITE)
            {
               return XsDateTime.Null;
            }
            else
            {
               return _end;
            }
         }
         set
         {
            if (value.IsNull)
            {
               _end = INFINITE;
            }
            else
            {
               _end = value;
            }
         }
      }


Is the attribute [component] correctly defined?

What is the attribute I can use to create a property using that component?

Thanks !!

-daV


Top
  
 
 Post subject: Re: How to use a <component> with Hibernate.Mapping.At
PostPosted: Fri Aug 19, 2005 8:39 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Hi,

Your situation is a good usage case of <component>.

As <component> must be in a <*class>, your Component class must also be in a mapped class.

Here is an example showing what you can do to share a component with many classes:

Code:
// DON'T MAP THIS CLASS
public class ValidityPeriod
{
   [Property]
   public DateTime Begin { ... }
   [Property]
   public DateTime End { ... }
}

[Class]
public class Entity1
{
   [Component]
   private class Entity1ValidityPeriod : ValidityPeriod {}
   // Here, Entity1ValidityPeriod will inherit properties of ValidityPeriod
}

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


Top
 Profile  
 
 Post subject: Thank you
PostPosted: Tue Aug 23, 2005 9:19 am 
Thank you, it helps me a lot.

The [component] do not seem to be inheritable such as typical properties. Is it normal? or is there a problem in my implementation?

Thx,


Top
  
 
 Post subject: Re: Thank you
PostPosted: Wed Aug 24, 2005 8:52 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
-daV wrote:
The [component] do not seem to be inheritable such as typical properties. Is it normal? or is there a problem in my implementation?


Class-level attributes are not inherited; that's a design choice...

_________________
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.  [ 4 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.