如何使用hibernate标准连接表

时间:2012-05-16 14:11:11

标签: java hibernate criteria

我正在尝试使用条件加入多个表来加入,但是这样做会出错,有人可以帮助我 我的代码是

final Session session = getSession();
final Criteria criteria = session.createCriteria(ReferralPaymentInfo.class).createCriteria("SIGNUP_REFERRAL");
System.out.println("before");
List list = criteria.list();
System.out.println("after");

我也试过这段代码     最后的Session session = getSession();     final Criteria criteria = session.createCriteria(ReferralPaymentInfo.class);     criteria.setFetchMode(" SIGNUP_REFERRAL",FetchMode.JOIN);     列表list = criteria.list();

这仅从表ReferralPaymentInfo中提供结果,而不考虑表SIGNUP_REFERRAL 有人可以帮助我 Ť

1 个答案:

答案 0 :(得分:0)

试试这个

DetachedCriteria ownerCriteria = DetachedCriteria.forClass(Owner.class);
    ownerCriteria.setProjection(Property.forName("id"));
    ownerCriteria.add(Restrictions.eq("ownername", "name"));

    Criteria criteria = getSession().createCriteria(Pet.class);
    criteria.add(Property.forName("ownerId").in(ownerCriteria));