Skip to content

Instantly share code, notes, and snippets.

@mpurbo
Created June 17, 2011 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mpurbo/1030830 to your computer and use it in GitHub Desktop.
Save mpurbo/1030830 to your computer and use it in GitHub Desktop.
Hibernate many-to-many Criterion
Criteria criteria = session.createCriteria(Programmer.class);
criteria.add(Restrictions.sqlRestriction(
"EXISTS(" +
"SELECT pp.programmer_id " +
"FROM programmers_projects pp " +
"WHERE " +
"pp.programmer_id = {alias}.programmer_id AND " +
"pp.project_id IN (1, 2) )"
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment