Here's my own answer to myself in case anybody else can use it.
I used an object derived from EnhancedUserType (this is used instead of UserType because I want to use this type as a discriminator) and used a discriminator routed through my UserDefinedType. Here's snippets of the details. The column that has the range of values is CATEGORY. That's mapped normally. I defined a discriminator with a formula of CATEGORY. That just selects the CATEGORY column along with the other "normal" columns but routes it through the UserDefinedType I created.
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="MyBaseClass" table="TEST" discriminator-value="0">
<id name="id" type="integer">
<column name="MYID" />
<generator class="native" />
</id>
<discriminator formula="CATEGORY" type="MyUserType" />
<property name="category" type="integer">
<column name="CATEGORY" not-null="true" />
</property>
</class>
</hibernate-mapping>
In the MyUserType class I just implemented nullSafeGet to check for ranges of values and return simple values instead...something like this :
Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
throws HibernateException, SQLException {
Number result = (Number) rs.getObject(names[0]);
if (result == null)
return null;
Integer val = new Integer(result.intValue());
if (val >= 1 and val <= 100)
val = 1;
else if (val >= 101 and val <= 156)
val = 2;
return val;
}
This lets me subclass in the xml in the standard way with a single value.
Code:
<subclass name="MyDerivedClass1" discriminator-value="1" />
<subclass name="MyDerivedClass2" discriminator-value="2" />