Hi,
I have a semi-complex (overly complex really) structure of classes that inherit from each other. Basically it's an @Entity Abstract Class which is extended by about 6 other types of classes, all of which are also @Entity types. For some reason if I map the Abstract Class with inheritance based on Table_per_class I receive the following error when selecting (using criteria) against one of its sub types:
"Caused by: java.sql.SQLException: Types 'VARCHAR' and 'INTEGER' are not UNION compatible."
However if I change the inheritance mapping to JOINED then the error goes away and my code works just fine. (When I say works I mean there is a JUnit test that checks all the values of the loaded class and validates them so I know this is working with JOINED)
More details:
The base Abstract Class defines many different columns while the sub types simply add an additional column or two as well as a @OneToMany or a @ManyToMany relationship.
One of these subtypes has a @ManyToMany that is mapped to a targetEntity of the Abstract Class itself. When I do a NaturalId based Criteria search for this particular subtype the queries become very long, complex, and difficult to understand. From what I can see it selects from all of the possibly sub types and does a UNION ALL between all of the selects. These selects consist of all possible fields (with Nullif(0,0) for possibly non-existant fields) however they are clearly not all the same type. Many of my fields are String, many others are Integers. The final select does the actual foreign key checking and that all looks fine as well.
Unfortunately, according to the error, a UNION ALL cannot be used across different column types. Is this true? If so does this appear to be a Hibernate bug or a mistake on my part?
Apologies if there is any lack of detail but I think it should be pretty clear to someone with more SQL experience than me as to whether or not this sounds like a Hibernate bug and simply providing my code would only lead to confusion (my base type has something like 16 fields) unless I wrote minimal-bug testing code which I plan to if this appears to be a bug.
|