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.  [ 3 posts ] 
Author Message
 Post subject: Can you 'expand' a table into collections of collections
PostPosted: Wed Jul 05, 2006 2:37 am 
Newbie

Joined: Wed Jul 05, 2006 2:16 am
Posts: 6
Is it possible (or even a good idea) to expand a table into a collection of collections.

Example scenario:

I want to have a Log class that contains log entries for different machines (with hard coded machine or role names) for different sites.

ie each Site has three machine roles, domain controller, database server and exchange server, and I want my Log class to be contain all of the entries for each machine role at a particular site.

Code:
class Log
{
  public int SiteId {get;set;}
  public LogEntryCollection DomainControllerLogs {get;set;}
  public LogEntryCollection DatabaseServerLogs {get;set;}
  public LogEntryCollection ExchangeServerLogs {get;set;}

  //...
}

class LogEntryCollection : IList<LogEntry>
{
  AddNewEntry(string message, string messageType);

  //...
}

class LogEntry
{
  private int LogEntryId {get;set;}
  public string Message {get;set;}
  public string Type {get;set;}
  public string MachineRole {get;set;}
  public DateTime LogTime {get;set;}

  //...
}



I think I could map this without too much effort into three tables, but is it possible to create a map that will allow all entries to be placed into a single table. The table would look like this:


Code:
EntryId     | int <PK>
SiteId      | int <FK>
MachineRole | varchar(50)
Message     | varchar(50)
Type        | varchar(10)
LogTime     | DateTime


Is this possible or am I living in a dream?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 2:19 pm 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
Check out Chapter 10 of the Reference Manual (ver 3.0.5).

I believe section 10.1.1 shows how to do what you describe.

HTH,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 9:38 pm 
Newbie

Joined: Wed Jul 05, 2006 2:16 am
Posts: 6
Thanks for the reply.

Correct me if I'm mistaken, but I don't think "Table per class heirarchy" (section 10.1.1 in 3.0.5 reference) is an applicable solution.

I probably haven't explained myself well.

Using my example scenario code, I would like to be able to perform the following operation.

Code:
Log log = session.Load<Log>(logId);

foreach(LogEntry entry in log.DomainControllerLogs)
{
  // do something
}

LogEntry entry = new LogEntry();
entry.Message = "New message";
entry.Type = "Debug";
entry.LogTime = DateTime.UTCNow;

log.ExchangeServerLogs.Add(entry);

session.SaveOrUpdate(log);


As far as the table is concerned it could look something like this:

Code:
| EntryID | SiteID | MachineRole      | Message     | Type  | LogTime          |
================================================================================
| 1       | 1      | DomainController | Existing .. | Info  | 2006/06/07 10:12 |
| 2       | 1      | ExchangeServer   | New Message | Debug | 2006/06/07 11:12 |


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.