Hibernate version: 2.0
In my db schema there is a concept of a base table and an override table that is one-to-many. That is each override table
may override properties of the base table. My domain model has an separate object for each table, where the override object contains a reference to the base table and override properties are proxied via the base object. In addition the override object is part of a polymorphic structure. Here is a sample:
Code:
public class BaseObject
{
private string _one;
public virtual string One
{
get {return _one;}
set {_one = value;}
}
private int _categoryID;
public virtual string CategoryID
{
get {return _categoryID;}
set {_categoryID= value;}
}
}
public class OverrideObject
{
private BaseObject _base;
public virtual BaseObject Base
{
get {return _base
set {_base = value;}
}
private string _one;
public virtual string One
{
get
{
if (string.IsNullOrEmpty (_one))
return Base.One;
return _one;
}
set {_one = value;}
}
//for persisting
public virtual string P_One
{
get {return _one;}
set {_one = value;}
}
}
public class OverrideSubClass:OverrideObject
{
private string _two;
public virtual string Two
{
get {return _two;}
set {_two= value;}
}
}
Here is the mapping for the override:
Code:
<class name="OverrideObject" table="OverrideTable">
...
<!-- here is where I want to create a formula to call Base.CategoryID -->
<discriminator column="CategoryID" />
<property column="One" name="P_One" type="String"/>
<many-to-one name="Base" class="BaseObject" column="BaseID"/>
<subclass name="OverrideSubClass" discriminator-value="1" >
<property column="Two" name="Two" type="string"/>
</subclass>
What I would like to do is alias the many-to-one object 'Base' and call it in the discriminator. I'd rather not place SQL in the formula to join on the table, because the join is already happening in the many-to-one association. Any thoughts?