-->
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.  [ 5 posts ] 
Author Message
 Post subject: Help needed - Value/lookup tables best practice
PostPosted: Sat May 10, 2008 5:24 am 
Newbie

Joined: Sat May 10, 2008 4:27 am
Posts: 1
Hello,

This is the first time i'm using orm instead of typed dataset.
I decided to use nhibernate v 2.0 to handle my data entities.

The topic is a bit long but the question is pretty simple.

I'm programming application for insurance office.
* Framework - C# .net 3.5
* Database - MSSQL 2005
* Architecture - Client-Server (using wcf)

My question relates "Value tables" (aka "lookup tables"). Assuming i have a "Person Entity" with "Status".

Database ERD (Partial)

Table Person
ID | Bigint
FirstName | nvarchar(50)
StatusID | int

Table PersonStatus
ID | int
Value | nvarchar(20)

In my previous applications, I usually seperated between two actions:
Editing Action
For editing purpose I used to extract the 'StatusID' value for the 'Person' entity (and not 'Status' entity).
In the UI layer - I'm using combobox from which the user select the relevent status.

Viewing Action
For viewing purpose i used to extract the 'Status Value' for the 'Person' entity using join sql.
In the UI layer - i only display the value. This way the sql handles the extraction of the relenet value and not the UI layer.

finally, my question:
I understand how to use nhibernate for the 'Editing Action' (using the 'table per subclass' strategy and extract the actual id value).

How to perform the 'Viewing Action'? i don't want to extract 'Status' entity for each 'Person' entity only the actual value as simple type.

What is considered as best practice in this situation.

Many thanks for the help.
Eran Sakal.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 11, 2008 4:54 am 
Newbie

Joined: Sun May 11, 2008 4:40 am
Posts: 1
Location: Israel
Hi Eran,
I think that the good practice for "lookup tables" (such as Status table),
is to create static table (without Entity) or to create text files
that will handle all "lookup tables".
To create an Entity for those static data will be an "Overhead" to your application.

BR,

_________________
Yaron Ismah-Moshe
MetaLogic CEO
yaron@metalogic.co.il


Top
 Profile  
 
 Post subject: Many-To-One
PostPosted: Mon May 12, 2008 3:10 pm 
Newbie

Joined: Mon May 12, 2008 3:08 pm
Posts: 2
maybe i'm missing something but why not use

<many-to-one name="PersonStatus" class="FullClassName, AssemblyName" column="StatusID"/>

and make sure that you have a class called PersonStatus
that has both id (int) and value (string)

that way you can get either value or the name by using

objPerson.Status.ID or objPerson.Status.Name

hopefully that helps..


Top
 Profile  
 
 Post subject: Help needed - Value/lookup tables best practice
PostPosted: Thu May 15, 2008 2:19 pm 
Newbie

Joined: Thu May 15, 2008 2:10 pm
Posts: 1
Location: Seattle, WA
That seems like a sound way to go, raanan.raz, for the Person class, but how would you be able to populate a drop-down of PersonStatuses?

I'm facing the same problem. There seems to be no support for top-level collections that aren't contained or referenced by class entitites.


Top
 Profile  
 
 Post subject: LoadAll
PostPosted: Tue May 20, 2008 2:55 am 
Newbie

Joined: Mon May 12, 2008 3:08 pm
Posts: 2
I'm using spring so here is an example.. but it's the same for the basic
hibernate
return HibernateTemplate.LoadAll(typeof(PersonStatus));
will return a IList with all the PersonStatuses inside..

now all that is left is to bind it to a control..

hope that helps


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