0
SELECT * FROM test.pchi new INNER JOIN rlhi old ON new_id = old.menu_id where new.name='?'

Similar to:

Select * from db.employee emp INNER JOIN db.table on emp_tableID = table.id where emp.name = '?'

If you could tell me how to do a projection, that would be awesome... as in:

Select emp.name, emp.sex, table.brand from ....

I tried using fetch, but I'm very new to this and keep getting some weird errors. Could someone please demonstrate how to do this?

How about this?

sess.createCriteria(pchi.class)/**/
              .setFetchMode("rlhi", FetchMode.JOIN)
              .add(Restrictions.eq("new_id", "rlhi.menu_id"))
              .add(Restrictions.eq("name", "SOME INPUT"))
4

1 回答 1

1
sess.createCriteria(Pchi.class)
              .setFetchMode("rlhi", FetchMode.JOIN) //note that rlh1 is the property name in Pchi class
              .add(Restrictions.eq("name", "SOME INPUT"));

在你的课堂上你有这样的东西

class Pchi{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="new_id", referencedColumnName="menu_id")
private Rlhi rlhi;
}

class Rlhi{
@OneToMany(mappedBy="rlhi")
private <Set> Pchi pchis;
}

注意当您使用时SET应该覆盖equals()hashCode()方法才能正常工作

于 2013-06-12T00:51:12.853 回答