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 user
s 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 work
s 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
Post a Comment