【发布时间】:2022-01-20 04:41:18
【问题描述】:
假设我有以下实体类:
@Entity public class MyEntity {
@Id private String id;
@ManyToOne private MyOtherEntity myOtherEntity;
}
@Entity public class MyOtherEntity {
@Id private String id;
@Column private String name;
}
现在我想做一个查询来获取所有链接到某个MyOtherEntity的MyEntitys,我想知道以下3个谓词之间的区别:
cb.equal(root.get(MyEntity_.myOtherEntity), myOtherEntity);
cb.equal(root.get(MyEntity_.myOtherEntity).get(MyOtherEntity_.id), myOtherEntity.getId());
cb.equal(root.get(MyEntity_.myOtherEntity).get(MyOtherEntity_.name), myOtherEntity.getName());
在每种情况下生成的 SQL 会是什么样子?哪一种效率最高?
【问题讨论】: