-->
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: How best to "enumerate" persistent classes?
PostPosted: Tue Feb 07, 2006 10:25 am 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
There are a few situations in the project I am working on where I need to "enumerate" a few of my persistent classes and I was wondering how other people were tackling this problem.

So for example, let's say we have a persistent class ProductType. Then let's say there are 2 types (and that is unlikely to change), TypeA and TypeB.

So in the style of an enumerator, we want to be able to reference ProductType.TypeA and ProductType.TypeB in our domain model. For example, we might want:

if( order.Contains( ProductType.TypeA ) )
{
// Some logic here...
}

Let's now say that ProductType has a Name property whose value we want to draw from the database. So an enumerator won't do because we won't have access to the Name property.

One approach is to use public static readonly fields on the ProductType class:

public static readonly ProductType TypeA = new ProductType( 1, "Type A" );
public static readonly ProductType TypeB = new ProductType( 2, "Type B" );

The problem with this approach is that we have the Name property embedded in the code as well as in the database. This problem grows substantially as the number of properties grows and associations are added to other persistent classes.

Is there a "best practice" approach to handling this situation?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 07, 2006 8:46 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
I might add also that we don't want to be referencing any persistence-related concerns from our domain model, so having the public static readonly fields on the ProductType class read from the database doesn't seem possible.


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.