Skip to content Skip to sidebar Skip to footer

Hibernate Or Sql Query M-n Member Of With Collections?

Given a class which has an @ElementCollection of Strings, and given an input collection of Strings: public class FooBar { @ElementCollection private Set tags }

Solution 1:

  1. select fb 
    from FooBar fb 
    left join fb.tags t
    where t in ( :queryTags )
    
  2. select fb 
    from FooBar fb 
    where fb.id not in (
        select id
        from FooBar
        left join tags t
        where t not in ( :queryTags )
    )
    

Where the queryTags is set with:

session.createQuery(queryString).setParameterList( "queryTags ", queryTags ).list();

Post a Comment for "Hibernate Or Sql Query M-n Member Of With Collections?"