Milad Khajavi Milad Khajavi - 11 months ago 89
Java Question

Join two table using Criteria in Hibernate?

I have query like this written in hql format:

Query qq = session.createQuery(
"select question from Question question " +
"join question.information.tags t1 " +
"join question.information.tags t2 " +
"where = 'java' and = 63"

I wrote this query in Criteria format but it trow exception:

session.createCriteria(Question.class, "q")
.createAlias("q.information.tags", "t1")
.createAlias("q.information.tags", "t2")
.add(Restrictions.eq("", "63"))
.add(Restrictions.eq("", "java"))

Method threw 'org.hibernate.QueryException' exception.:
duplicate association path: information.tags

What is the problem? Any way to write hql in Criteria format?

Answer Source

I don't think it is possible to join the same association twice with Criteria

You can find the related JIRA here that is still open.