-->
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 can i map these entiites??????
PostPosted: Fri Feb 23, 2007 3:18 pm 
Newbie

Joined: Fri Feb 23, 2007 2:05 pm
Posts: 2
CREATE TABLE [Entity]
(
[id] [int] IDENTITY (1, 1) NOT NULL ,
[name] [varchar] (50) NULL ,
[type] [varchar] (10) NULL
) ON [PRIMARY]

CREATE TABLE [EntityCompany]
(
[comp_id] [int] IDENTITY (1, 1) NOT NULL ,
[entity_id] [int] REFERENCES Entity.id
[company_type] [tinyint] NOT NULL
) ON [PRIMARY]

CREATE TABLE [EntityPerson]
(
[person_id] [int] IDENTITY (1, 1) NOT NULL ,
[entity_id] [int] REFERENCES Entity.id
[email] [varchar] (50) NULL ,
[phone] [varchar] (12) NULL
) ON [PRIMARY]

I want to map this entities in a class hierarchy using NHibernate but it seems to be impossible. I tried using <joined-subclass> but this way uses the inherited ID for the subclasses, and i want to use the subclass own ID, but also get the values of the inherited properties. Anyone knows if it is any way of achieving this? Thxs.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 24, 2007 3:14 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
What your tables are suggesting is the Decorator pattern. So you'd wrap an Entity class within your EntityCompany and EntityPerson classes, delegating underlying properties to the inner object.
Personally, I prefer this pattern over subclassing whenever possible anyways.
Code:
public class EntityCompany : Entity
{
   private Entity _inner;
   public EntityCompany(Entity entity)
   {
      _inner = entity;
   }
   public SomeProperty
    {
       get{return _inner.SomeProperty;
    }
}

If you insist on joined-subclass approach then I believe you'll need to implement some identifier to be unique in addition to the key NHibernate uses to subclass across tables.

MIKE[/code]

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 5:01 pm 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
I think that the entitycompany and entityperson stay in many-to-one relationship with entity rather since you can have svsral insances of entyticompany as well as entityperson referencing the entity.

There is no exclusion existing that would say you have either entitycompany or entityperson but them both. Furthermore it is not an error to have more than one entityprson or entitycompany per one entity.

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 26, 2007 8:41 am 
Newbie

Joined: Fri Feb 23, 2007 2:05 pm
Posts: 2
mnichols wrote:
What your tables are suggesting is the Decorator pattern. So you'd wrap an Entity class within your EntityCompany and EntityPerson classes, delegating underlying properties to the inner object.
Personally, I prefer this pattern over subclassing whenever possible anyways.
Code:
public class EntityCompany : Entity
{
   private Entity _inner;
   public EntityCompany(Entity entity)
   {
      _inner = entity;
   }
   public SomeProperty
    {
       get{return _inner.SomeProperty;
    }
}

If you insist on joined-subclass approach then I believe you'll need to implement some identifier to be unique in addition to the key NHibernate uses to subclass across tables.

MIKE[/code]


Already figured out this same solution, thank you anyway!


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.