这是我的健康表实体:
@Table(name="health")
public class Health implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="hid")
private int hid;
@Column(name="ivid")
private int ivid;
@JoinColumn(name = "nwid")
@ManyToOne(fetch = FetchType.LAZY)
private Networks nwid;
}
我正在尝试获取一个健康行,网络表中没有任何可用的内容,这就是为什么它没有给我健康表的行记录..
我想从健康中获取该行,我不希望它查看该记录的网络表..
如果我不使用crit.createAlias ...服务器调用失败。
try
{
session = sessionFactory.openSession();
Criteria crit = session.createCriteria(Health.class);
crit.createAlias("nwid", "network");
crit.createAlias("network.statsId", "stats");
crit.add(Restrictions.eq("ivid", 0));
Iterator<Health> it = crit.list().iterator();
while(it.hasNext()){
health = it.next();
}
答案 0 :(得分:0)
尝试改变这一点:
crit.createAlias("nwid", "network");
到
crit.createAlias("nwid", "network", CriteriaSpecification.LEFT_JOIN);