我有这个实体:
@Entity
@Table(name = "GDO.NEWS")
public class News implements Serializable, GenericType {
@Id
@Column(name="ID", insertable=true, updatable=false)
protected Integer id;
@OneToMany(fetch=FetchType.LAZY)
@JoinTable( name = "GDO.NEWS_FILTRO" , joinColumns = @JoinColumn(name = "ID_NEWS") ,
inverseJoinColumns = @JoinColumn(name= "ID_FILTRO", referencedColumnName = "ID_FILTRO") )
private Set<FiltroRegione> filtroRegione;
}
与此实体的OneToMany关系:
@Entity
public class FiltroRegione extends AbstractFiltro {
//... does not matter
}
扩展了这个类:
@Entity
@Table(name = "GDO.FILTRO")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "CLASSE_FILTRO", discriminatorType=DiscriminatorType.STRING)
public class AbstractFiltro implements java.io.Serializable, GenericType {
private static final long serialVersionUID = 1L;
@Id
@Column(name="ID_FILTRO", insertable=true, updatable=false)
private Integer id;
@Column(name="TIPO_FILTRO")
protected String tipoFiltro;
public AbstractFiltro() {
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
关键点新闻实体中的@OneToMany关联不仅返回FiltroRegione实体,还返回AbstractFiltro所有子类的实体(它们共享相同的数据库表GDO.FILTRO,但有一个鉴别器专栏)。
我认为问题是@JoinTable,如果连接表GDO.NEWS_FILTRO中有记录关联,它忽略了鉴别器列,只是从表GDO.FILTRO 中获取所有记录。来自GDO.NEWS的记录,记录来自GDO.FILTRO。
显然我想要我的Set&lt; FiltroRegione&gt;仅由FiltroRegione实体填充,实体存储在GDO.FILTRO中,其中包含&#34; FiltroRegione&#34;作为鉴别器列的值。我怎样才能获得这种行为?
我被迫使用OpenJpa 1.x,支持JPA 1.0规范