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 FileCode:
<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.