JPA如何使用InheritanceType.JOINED配置外部联接 [英] JPA how to configure outer join with InheritanceType.JOINED

查看:461
本文介绍了JPA如何使用InheritanceType.JOINED配置外部联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有InheritanceType.JOINED的域模型.

I have a domain model with InheritanceType.JOINED.

@Table(name = "S_MC_CC_RAPPORTI")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "COD_TIPORAPPORTO")
public class RapportoImpl implements Rapporto, Cloneable {

    @Id
    @Column(name = "COD_RAPPORTO")
    protected Long codiceRapporto;

和子类:

@Entity
@Table(name = "CARTE")
@DiscriminatorValue("4 ")
public class CartaImpl extends RapportoImpl implements Carta, Cloneable {

    private static final long serialVersionUID = 1723366781345274590L;

这很好,直到数据库一致为止.

This works great until the DB is consistent.

Rapporto

Id   COD_TIPORAPPORTO
1       4

Carte

Id   Description
1     Carta

因此,当我通过id 1加载Rapporto时,一切都很好.但是,当数据库不一致时,所有的工作都会变坏.
想象一下,我在子表Carte上没有更多记录了.当我尝试加载它时,我得到一个null对象,因为JPA在超级表和子表之间建立了内部联接. 是否可以通过在子表上进行外部联接的方式进行配置

So when I load a Rapporto by id 1 all works great. But when the db goes inconsistent all works bad.
Imagine that I have no more the record on the child table Carte. When I try to load it I get a null object because JPA makes an inner join between super and child table. Is it possible to make configure it in a way to make an outer join on the child table

推荐答案

总结-如果您的JPA提供者是EclipseLink,则比

To sum up - if your JPA provider is EclipseLink than there is a way to say that it should use OUTER JOINs when fetching child objects in join inheritance strategy.

这篇关于JPA如何使用InheritanceType.JOINED配置外部联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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