Hibernate 检索返回空列表,而填充列表是预期的。涉及2个对象,由注解完成映射:
@Entity
@Table(name = "parent")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Parent {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private long id;
}
@Entity
@Table(name = "child")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
class Child {
@ManyToOne
@JoinColumn(name = "parentId")
@OrderBy(value="id")
private Parent parent;
}
执行的查询:
String queryString = "select c from Child c where c.parent.id = ?1";
Query q = getEntityManager().createQuery(queryString);
q.setParameter("1", parentId);
return q.getResultList();
当休眠执行该组代码时,它返回一个大小 = 0 的列表。打开 SQL 登录并执行 MAMP 中日志中提供的查询会返回预期结果,任何人有什么想法吗?