-->
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.  [ 1 post ] 
Author Message
 Post subject: many-to-many implemented as many-to-one
PostPosted: Tue Nov 15, 2005 5:29 am 
Hi all,

I have just started using nHibernate and would appreciate any help with a solution for following mapping scenario.

Domain Objects

The domain objects are Employee and Access Cards. An Employee can have multiple types of Abstract Access cards such as Permanent Card, Temporary Card, Special Previlege Card.

A permanent card is always linked to an Employee.

A temporary card is only issued when an employee loses or forgets his card and is activated for a pre-set number of days. Temporary Cards are re-used. A temporary card may or may not be linked to an employee at any given time.

A Special Previlege Card is given to external consultants and is not linked to an Employee.

PermanentCard, TemporaryCard and SpecialPrevCard are all derived from AbstractAccessCard.

Employee has a IDictionary of AbstractAccessCards and in turn AbstractAccessCard refers to an Empoyee Object.

Database Tables
The database tables are Employees, EmpAccessCards and AccessCards. EmpAccessCards table is used for breaking the many-to-many relationship (for rotation of Temporary Cards). For Permanent cards there is only one instance per card in EmpAccessCards. For Special Previlege cards there is no entry in EmpAccessCards as they don't belong to any employee.


Although in the domain objects the relationship between Employee and Access Cards is one-to-many in database implementation it's many-to-many as Temporary cards can be rotated between employees. But at any one time only one instance of temporary card is actively linked to a employee based on date field in EmpAccessCards table.

My Question
Now in my mapping files I can't use many-to-many relationship as the domain objects see this only as a one-to-many or many-to-one relationship whilst the database implementation is a many-to-many?

Also is there a way to map a class to multiple tables instead of only one table and use where clause?

If the issue is unclear pls let me know and I will attach a domain model and ER Diagram.

Regards,
Kal


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.