JPA如何使用InheritanceType.JOINED配置外部联接 [英] JPA how to configure outer join with 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
推荐答案
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屋!