Hibernate version: 3.0.5
Hi,
I am having difficulty working out the correct mapping to use for a one-to-many relationship to an interface. I'm sure that this question has been asked before, but after doing a fair bit of reading and searching on the forums I have yet to find a solution.
Consider the following class hierarchy (which is a subset of my actual class hierarchy):
Code:
public abstract class Persistent{
private Long id;
private int version;
...
}
public interface FormulaInput{
public double getInputValue();
}
public class Constant extends Persistent implements FormulaInput{
...
}
public class Entry extends Persistent{
...
}
public class NumericEntry extends Entry implements FormulaInput{
...
}
public class Formula extends Persistent implements FormulaInput{
private Set<FormulaInput> inputs = new HashSet<FormulaInput>();
...
}
When mapping this kind of structure I have been using <joined-subclass> to do table per subclass mapping. I have not mapped the interface, so I have tables t_persistents, t_constants, t_entrys, t_numeric_entrys and t_formulas. I've been using XDoclet2 to generate the mapping files, and Hibernate Tools to generate the database schema.
Now my problem is that I've so far not been able to work out how to map the input property of the Formula class. Ordinarily, I would just use a <one-to-many> inside a <set>. However, as FormulaInput is not mapped I cannot use it as the value of the class attribute in the <one-to-many>. Even if I did map the FormulaInput interface to a table, the Constant and NumericEntry classes would then have to be joined subclasses of two classes, which I don't think can be done.
Has anyone got any ideas as to how I could map this class hierarchy?
Thanks in advance,
Rob