-->
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: Many components of one type in persistent class
PostPosted: Thu Dec 08, 2005 1:28 am 
Newbie

Joined: Thu Jul 21, 2005 7:24 am
Posts: 2
I have a class to be mapped as a component that contains several properties, for example, DAY, MONTH and YEAR. The class is decoreated
with [Component()] attribute.

In a master-class I have several properties of this type each decorated
with [ComponentProperty()].

Code:
[Component()]
public class MyComponent
{
  [Property()]
  public int Days
  {get {...};set {...};}
  [Property()]
  public int Months
  {get {...};set {...};}
  [Property()]
  public int Years
  {get {...};set {...};}
}

[Class()]
public class MyPersistentClass
{
  [ComponentProperty]
  MyComponent OneProp
  {get {...};set {...};}

  [ComponentProperty]
  MyComponent TwoProp
  {get {...};set {...};}

  [ComponentProperty]
  MyComponent ThreeProp
  {get {...};set {...};}
}


As a result, all three properties "Days" from "OneProp","TwoProp" and "ThreeProp" are mapped to the same DB column. That is also true for "Years" and "Months".
Unfortunately, I have found no ways to specify different columns in [ComponentProperty()] .


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 11:19 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
The only solution I can think of is to do:
Code:
[Component()] // These attributes become optional
public class MyComponent
{
  [Property()]
  public int Days
  {get {...};set {...};}
  [Property()]
  public int Months
  {get {...};set {...};}
  [Property()]
  public int Years
  {get {...};set {...};}
}


[Class()]
public class MyPersistentClass
{
  MyComponent OneProp
  {get {...};set {...};}

  [Component(Name="OneProp")]
  public class MyComponent_OneProp
  {
    [Property(Column="Days_OneProp")]
    public int Days
    {get {...};set {...};}
    [Property(Column="Months_OneProp")]
    public int Months
    {get {...};set {...};}
    [Property(Column="Years_OneProp")]
    public int Years
    {get {...};set {...};}
  }

  ...
}

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 1:31 am 
Newbie

Joined: Thu Jul 21, 2005 7:24 am
Posts: 2
And what shall i do with many functions in my program taking MyComonent arguments?

Code:
class MyComponent
{
   public virtual Prop
  {
     get{...}set{...}
  }
}
[Class]
class MyClass
{
   [Component]
   class OneMyComponent: MyComponent
   {
       [Property(Column="ONECOMP_ONEPROP")]
       public override Prop
       {
           get {return base.Prop;}
           set {base.Prop = value;}
       }
   }
   
  [ComponentProperty()]
  OneMyComponent OneComp
  {
     get{...}set{...}
  }
}


right?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 4:35 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Two little corrections:
Code:
class MyComponent
{
   public virtual Prop
  {
     get{...}set{...}
  }
}

[Class]
class MyClass
{
   [Component(Name="OneComp")]
   class OneMyComponent: MyComponent
   {
       [Property(Column="ONECOMP_ONEPROP")]
       public override Prop
       {
           get {return base.Prop;}
           set {base.Prop = value;}
       }
   }

  OneMyComponent OneComp
  {
     get{...}set{...}
  }
}


Mapped classes (components, subclasses) which are nested in another mapped parent class are automatically included in the mapping of this parent class; so if you use [ComponentProperty], you will have this information twice in the mapping.

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