怎么了?
session.createCriteria(Composed.class, "main") .createAlias("main.id.branch", "b1") .add(Restrictions.eq("b1.owner", user)) .list();
?相应的HQL工作正常
String hql = "select main from Composed as main" + "left join main.id.branch as b1 where b1.owner = ?"; session.createQuery(hql) .setInteger(0, user.id().intValue()) .list();
从Criteria开始,Hibernate没有创建任何连接和使用where b1x1_.owner_id=?
,但是没有b1x1_
任何地方,所以它失败了"无法准备语句".
这些课程相当简单
@Entity class Composed { @Id ComposedId id; // also tried @EmbeddedId ... irrelevant stuff } @Embeddable class ComposedId { @ManyToOne(optional=false) Branch branch; ... irrelevant stuff } @Entity class Branch { @Id Integer id; @ManyToOne(optional=false) User owner; ... irrelevant stuff } @Entity class User { @Id Integer id; ... irrelevant stuff }更新
我终于创建了一个SSCCE并提出了一个问题.很抱歉这个令人困惑的问题,没有SSCCE,重现起来相当困难.