开发者

Hibernate TABLE_PER_CLASS with @MappedSuperclass won't create UNION query

开发者 https://www.devze.com 2023-03-18 04:58 出处:网络
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 tab开发者_

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 tab开发者_Go百科les, 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)?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消