Filtering collections in Hibernate by R4R Team

The returned collection is considered a bag that is a copy of the given collection. The original collection is not modified. This is contrary to the implication of the name "filter", but consistent with expected behavior.

Observe that filters do not require a from clause, although they can have one if required. Filters are not limited to returning the collection elements themselves.

Collection blackKittenMates = session.createFilter(sp.getKittens(), 
    "select this.mate where this.color = r4r.Color.BLACK.intValue")

Even an empty filter query is useful, r4r to load a subset of elements in a large collection:

Collection tenKittens = session.createFilter(mother.getKittens(), "")

A collection filter is a special type of query that can be applied to a persistent collection or array. The query string can refer to this, meaning the current collection element.

Collection blackKittens = session.createFilter(sp.getKittens(), 
    "where this.color = ?")
    .setParameter( Color.BLACK, Hibernate.custom(ColorUserType.class) )
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!