带有@MappedSuperclass 的休眠 TABLE_PER_CLASS 不会创建 UNION 查询 [英] Hibernate TABLE_PER_CLASS with @MappedSuperclass won't create UNION query

查看:29
本文介绍了带有@MappedSuperclass 的休眠 TABLE_PER_CLASS 不会创建 UNION 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一系列对象,这些对象都存储在单独的表中,但是所有这些表上有一组共同的字段.我希望 Hibernate 对所有这些表进行联合,但不包括作为表的超类.

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.

当我只用以下内容注释超类时:@MappedSuperclass@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

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

...hibernate 将为超类的 (n) 个子类型分别运行 (n) 个查询.

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

当我删除@MappedSuperclass 并将@Entity 放在超类上时,Hibernate 将执行花哨的 UNION 查询,但将超类作为表包含在 UNION 中(超类没有表).

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).

如何在不使父类成为@Entity(因为它不是实体,没有表)的情况下将所有子类(不是单独的查询)一起使用 UNION?

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)?

推荐答案

我发现将父类标记为抽象"可以解决问题,Hibernate 不再将其包含在 UNION 中,did UNION将所有子类放在一起.

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.

这篇关于带有@MappedSuperclass 的休眠 TABLE_PER_CLASS 不会创建 UNION 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆