考虑到我有一个像这样定义的实体A
@Entity
public class A {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Version
@Column(name = "version")
private Integer version;
@OneToOne
private B b;
// getters & setters
}
和B,其定义如下:
@Entity
public class B {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Version
@Column(name = "version")
private Integer version;
private String x;
// getters & setters
}
我们还假设x
被编入索引。我的问题是,是否有一个普通的"明显的"查询来自A的x
之间的性能差异如下:
TypedQuery<A> query = entityManager.createQuery("SELECT a FROM A a where a.b.x = :x", A.class);
query.setParameter("x", "myX");
A a = query.getSingleResult();
直接从B中查询x
:
TypedQuery<Person> q = entityManager.createQuery("select b from B b where b.x = :x", B.class);
q.setParameter("x", "myX");
B b = query.getSingleResult();
如果重要的是我们正在使用MySQL 5.6。