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.  [ 2 posts ] 
Author Message
 Post subject: Mapping a class from a lookup table
PostPosted: Thu Jun 12, 2008 1:39 am 
Newbie

Joined: Wed May 28, 2008 3:17 am
Posts: 10
Hibernate version: 1.2.1 GA
Name and version of the database you are using: MS SQL 2k(5)

I'm wondering if its possible to map a class from a lookup table. I have a table that has a number of system wide settings and options in it (CM_OPTION), and I'd like to be able to pull a number of them out to populate a class. Is there an easy way to do this?

Code:
CREATE TABLE [dbo].[CM_OPTION](
[OPTION_ID] [int] IDENTITY(1,1) NOT NULL,
[SECTION_NAME] [varchar](15) NULL,
[OPTION_NAME] [varchar](60) NOT NULL,
[OPTION_VALUE] [varchar](4096) NULL,
...)

I have a class say,
Code:
class CompanyDetails {
  public string CompanyName;
  public string Address;
}

CM_OPTION contains the CompanyName and Address, where the SECTION_NAME is "CompanyDetails", and the OPTION_NAME and OPTION_VALUE are the property names and values I want to pull out.

I'm not expecting to be able to create a generic mapping for any class from the CM_OPTION table, however mapping the name / value pairs onto the properties just for the CompanyDetails class is hard enough! (unless I'm missing something!)

Thanks for any ideas
Phil


Top
 Profile  
 
 Post subject: Re: Mapping a class from a lookup table
PostPosted: Fri Jun 13, 2008 2:45 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
To answer your question:

philxan wrote:
Is there an easy way to do this?


No. This is orthogonal to the problem NH is designed to solve. Perhaps you could create a pivot view of the values in your table and map to that? Or if this is singleton, read-only info in your DB, you could map directly to the table, load it all once, and then do lookups to a hashtable in your app.


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