java - Hibernate criteria filter inner collection -


i have next classes/tables:

user

  • id
  • name
  • works // list of work

work

  • id
  • name
  • user_id

and following code:

criteria criteria = session.createcriteria("user");  criteria.list(); 

returns list of users contain list of work object assotiated them (by id=user_id).

how can modify query same list of user follow restriction: list of work should not includes works name ='fck'?

it's possible, not wise, because loaded users wouldn't reflect actual state of database : list of works should contain works, , not of them. modifying them lead unwanted deletes in database.

i rather load works you're interested in, associated user :

criteria c = session.createcriteria(work.class, "work"); c.createalias("work.user", "user"); c.setfetchmode("work.user", fetchmode.join); c.add(restrictions.ne("work.name", "fck")); 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -