Code:
@Entity
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public abstract class TE {
@Id
@GenericGenerator(name = "idGenerator", strategy = "assigned")
@GeneratedValue(generator = "idGenerator")
@Column(name="TE_KEY")
private String id;
@OneToMany
@JoinColumn(name="TA_KEY", referencedColumnName="TE_KEY", insertable=false, updatable=false)
private List<TA> taList;
}
public class TE1 extends TE {
}
public class TE2 extends TE {
}
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="ta_type")
public abstract class TA {
@Id
@GenericGenerator(name = "idGenerator", strategy = "assigned")
@GeneratedValue(generator = "idGenerator")
@Column(name="TA_KEY")
private String id;
public abstract void setTE(TE TE);
public abstract TE getTE();
}
@Entity
@DiscriminatorValue("TE1")
public class TA2 extends TA {
@ManyToOne(targetEntity=TE1.class)
@JoinColumn(name="TE_ENTITY_FK")
private TE TE;
public TE getTE() {
return TE;
}
public void setTE(TE TE) {
this.TE = TE;
}
}
@Entity
@DiscriminatorValue("TE2")
public class TA2 extends TA {
@ManyToOne(targetEntity=TE2.class)
@JoinColumn(name="TE_ENTITY_FK")
private TE TE;
public TE getTE() {
return TE;
}
public void setTE(TE TE) {
this.TE = TE;
}
}
Criteria crit = super.getSession().createCriteria(TA.class);
crit.createAlias("TE", "trk");
crit.add(Restrictions.like("trk.id", "%"));result in :
select ...............
from TA this_
inner join TE1 trk1_ on this_.TE_ENTITY_FK=trk1_.TE_KEY
inner join TE2 trk1_ on this_.TE_ENTITY_FK=trk1_.TE_KEY
where trk1_.TE_KEY like ?ORA-00918: column ambiguously defined.How to change my mapping to be able to query without any errors ?