I am having the same sort of problem and I AM using the table-per-heirarchy pattern. The problem is that I also have a complex graph.
I have a class A, which is flat, and classes B, C, D, and E, which are heirarchies, each heirarchy having a single table. Associations exist from A to B to C to D to E, all of which are many-to-one or one-to-one. Each subclass of B, for example, may have a different set of many-to-one associations to different subclasses of C.
I want to query like this:
Code:
from A a where a.foo = :foo
Now it is clear from the mappings that a proper query of this graph should result in not such a large graph and maybe 30 joins. However, the SQL query that results has almost 100 joins...basically it joins for every many-to-one or one-to-one association even though these are not relevant to the discriminator for the record I want. The result is "ORA-01792: maximum number of columns in a table or view is 1000".
I tried queries like
Code:
select b.a from subB b where b.a.foo = :foo
assuming I would use another query to get the sublass name, hoping that this would narrow the query, but it didn't help.
I am able to make small changes to the Java classes if necessary, but a refactoring of the object model is not permitted.
How can I get Hibernate to create a more directed query?[/quote]