我有以下情况:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Base implements Serializable {
@Id
private int Id;
private String fieldA;
private String fieldB;
@ManyToOne(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@Id
private ContainerOfAll owner;
//getters/setters...
}
@Entity
public class ConcreteA extends Base {
@Basic(optional=true)
private String someSpecialProp;
//getters/setters...
}
@Entity
public class ConcreteB extends Base {
@Basic(optional=true)
private String thing;
//getters/setters...
}
@Entity
public class ContainerOfAll {
@Id
private String containerId;
@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="owner")
private Set<Base> elements;
@OneToOne
private ConcreteA specificElement;
//getters/setters...
}
在EntityManager#find()
上调用ContainerOfAll
时,它将堆栈溢出。通过删除与新表的@OneToOne
关系来解决这个问题,新表将单个ContainerOfAll
建模为单个ConcreteA
。我所做的只是将private ConcreteA specificElement
转换为private int concreteAId
并在EJB方法中进行手动查找。
我的问题是,考虑到以下设置,如何在不添加表或不玩原始ID的情况下做到这一点?