Hi,
I'm not sure how to create that particular query.
It should be something like:
Code:
session.createCriteria( Entity.class, "e" )
.add( Subqueries.exists( DetachedCriteria.forClass(Entity.class)
.createAlias("e.props", "p")
.add( Restrictions.and( Restrictions.eqProperty( "p.name", "a" ), Restrictions.eqProperty( "p.value", "1" )) ) )
)
.add( Subqueries.exists( DetachedCriteria.forClass(Entity.class)
.createAlias("e.props", "p")
.add( Restrictions.and( Restrictions.eqProperty( "p.name", "b" ), Restrictions.eqProperty( "p.value", "2" )) ) )
)
;
But isn't your query equivalent to:
Code:
SELECT e
FROM Entity e INNER JOIN e.props p
WHERE (p.name = 'a' AND p.value='1') OR (p.name = 'b' AND p.value='2')
the criteria equivalent would be:
Code:
session.createCriteria( Entity.class )
.createAlias( "props", "p" )
.add( Restrictions.or(
Restrictions.and( Restrictions.eqProperty( "p.name", "a" ), Restrictions.eqProperty( "p.value", "1" ) ),
Restrictions.and( Restrictions.eqProperty( "p.name", "b" ), Restrictions.eqProperty( "p.value", "2" ) )
)
)
;
Note that I haven't tested these queries so I'm not sure they will work.
Hope this help,
Davide