【发布时间】:2011-12-04 20:05:33
【问题描述】:
我有一个带有 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;
在数据库保持一致之前,这很有效。
表Rapporto
Id COD_TIPORAPPORTO
1 4
表点菜
Id Description
1 Carta
所以当我通过 id 1 加载 Rapporto 时,一切都很好。但是当数据库不一致时,所有工作都不好。
想象一下,我在子表Carte 上没有更多的记录。当我尝试加载它时,我得到一个 null 对象,因为 JPA 在超级表和子表之间进行了内部连接。
是否可以对其进行配置以在子表上进行外部连接
【问题讨论】:
-
所以这是父表具有特定ID的行但没有子表行具有父行的FK的情况?
-
是的,情况就是这样。我必须在生产环境中处理此类情况。
-
执行一个特别要求超类的查询会有帮助吗?
-
我在 entitymanager 上查询超类 ase,如下所述:'RapportoImpl rapportoImpl = entityManager.find(RapportoImpl.class, 5l); assertNotNull(rapportoImpl);'
-
并且
rapportoImpl在这种情况下为空?
标签: inheritance jpa outer-join