Hibernate version: 3.2.3
Hi all,
I have a specification bug (not a functional one):
My example is very pedagogic: I have formulas (in groovy, java, ruby etc...) that may need each others in execution time. For tha purpose I made an object that can declare needed formulas. Each formula is in its own row. So a forumla can have be used in many other formulas, and can have many formulas it invokes: this is our many to many relathionship of Formula on itself.
Now formulas are classed in categories: let's say salary formulas and invoice formulas. Both have the same phylosophy.
Let's look at the formula class (uninteresting methods were removed):
Code:
@MappedSuperclass
public class Formula<F extends Formula>
implements Serializable {
protected Set<F> nestedFormulas, parentFormulas;
protected long id;
@ManyToMany
@JoinTable(name = "nested_formulas", joinColumns = @JoinColumn(name = "parent_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "child_id", referencedColumnName = "id"))
public Set<F> getNestedFormulas() {
return nestedFormulas;
}
@ManyToMany(mappedBy = "nestedFormulas")
public Set<F> getParentFormulas() {
return parentFormulas;
}
With this code, it is obvious that we will have our subclasses this way:
Code:
@Entity class SalarayFormula extends Formula<SalarayFormula> {}
Code:
@Entity class InvoiceFormula extends Formula<InvoiceFormula> {}
Generating the schema I realize there is one and only table nested_formulas with foreign keys on both SalarayFormula and InvoiceFormula. S it can't work because there is no "strategy" expression and no discriminator in the table or any other way to know if a many to many row is concerning this or that subclass entity.
There's an easy workaround (writing the dependencies in children classes but the specification should allow us to say: "I'd like to have one class for each dependency, or Id like tohave tem joined with a discrinatorstraegy"...
Any idea about doing things better?
Regards,
Zied Hamdi