我有3张桌子,RA,CC和EC。 RA有一个外键,' ec'它映射到'代码' EC表中的列。 RA还有另一个外键,' sc'它映射到'代码' CC表中的列。
@Entity
@NamedQueries({
@NamedQuery( name="getSettingsByCode, query="select object(o) from RA where o.sc.code = :someCode and o.ec.code is null" )
})
public class RA implements java.io.Serializable {
@Id
private long id;
private Timestamp recupdatetime;
@ManyToOne
@JoinColumn(name="SC")
private Cc sc;
@ManyToOne
@JoinColumn(name="EC")
private Ec ec;
Cc的实体
@Entity
public class Cc {
@OneToMany(mappedBy="sc")
private Set<RA> raCollection;
Ec的实体
@Entity
public class Ec {
@OneToMany(mappedBy="ec")
private Set<Recommendedalarmsetting> recommendedalarmsettingCollection;
执行namedQuery时,会生成以下sql,
[sql] SELECT t0.ID, t0.RECUPDATETIME, t0.EC, t0.SC FROM RA t0, EC t1 WHERE (
((t0.sc = ?) AND (t1.CODE IS NULL)) AND (t1.CODE = t0.ec))
这个SQL生成是否正确?我不确定IS NULL运算符是否生成了EC表的连接。