-->
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: Using a factory to serve a subclass instead of discriminator
PostPosted: Wed Aug 02, 2006 1:58 pm 
Newbie

Joined: Wed Aug 02, 2006 1:49 pm
Posts: 2
In my hierarchy I have a mapped object (Item) with multiple subclasses (C, S, R, N, I) and a discriminator value on the table. Inside the java I use a factory to serve up the exact item I need, and in the mapping file I have to use the discriminator. What I really want is to be able to use the factory in the mapping file so that there is only one place to update any more items and only one place with the conditional logic. Is this possible?

Factory
Code:
public class ItemFactory {

   public static Item getItemInstance(String str) {
      if (str.equalsIgnoreCase("C")) {
         return new CItem();
      }
      else if(str.equalsIgnoreCase("I")) {
         return new IItem();
      }
      else if(str.equalsIgnoreCase("N")) {
         return new NItem();
      }
      else if(str.equalsIgnoreCase("R")) {
         return new RItem();
      }
      return new SItem();
   }
}


Mapping File
Code:
<class  name="Item" table="item" discriminator-value= "O" >

<subclass name="item.CItem" discriminator-value="C" />
<subclass name="item.IItem" discriminator-value="I" />
<subclass name="item.NItem" discriminator-value="N" />
<subclass name="item.RItem" discriminator-value="R" />
<subclass name="item.SItem" discriminator-value="S" />


Much thanks in advance for any help.


Top
 Profile  
 
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.