Sean Molloy
Sean Molloy

Reputation: 121

Hibernate TABLE_PER_CLASS with @MappedSuperclass won't create UNION query

I am trying to create a series of objects that all are stored in separate tables, but that there is a set of fields in common on all these tables. I want Hibernate to do a UNION of all these tables, but NOT INCLUDE the superclass as a table.

When I annotate the superclass with just: @MappedSuperclass @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

...hibernate will run (n) queries separately for the (n) subtypes of the superclass.

When I remove @MappedSuperclass and instead put @Entity on the super class, Hibernate WILL do the fancy UNION query, but includes the superclass as a table in the UNION (there is no table for the superclass).

How do I get it to UNION together all the subclasses (not separate queries) without making the parent class an @Entity (because it's not an entity, there's no table for it)?

Upvotes: 4

Views: 2880

Answers (1)

Sean Molloy
Sean Molloy

Reputation: 121

I found that marking the parent class as "abstract" did the trick, Hibernate no longer included it in the UNION and did UNION together all the sub-classes.

Upvotes: 8

Related Questions