History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-13154
Type: New Feature New Feature
Status: Open Open
Assignee: Gregory Shrago
Reporter: Taras Tielkes
Votes: 0
Watchers: 4
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

Hibernate: Criteria API entity property resolving

Created: 07 Jun 07 10:34   Updated: 07 Jun 07 14:00
Component/s: J2EE.Hibernate

Build: 7,002


 Description  « Hide
In addition to HQL, Hibernate has the "criteria" API:
List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "F%")
    .addOrder( Order.asc("name") )
    .addOrder( Order.desc("age") )
    .setMaxResults(50)
    .list();

Since there's no language construct in Java to refer to a persistent property or field, string names are used.
Apart from simple example above, some more complex ones:
Creating new criteria on collection:

List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "F%") )
    .createCriteria("kittens")
        .add( Restrictions.like("name", "F%") )
    .list();

Using aliases:

List cats = sess.createCriteria(Cat.class)
    .createAlias("kittens", "kt")
    .createAlias("mate", "mt")
    .add( Restrictions.eqProperty("kt.name", "mt.name") )
    .list();

It seems that with some DFA and access to entity model, resolving could be provided for the property references in the Criteria API.
Of course not all scenarios can be covered, so references should be soft probably.

Even with limited support (meaning DFA has some restrictions etc), resolving (navigation/variants) for long entity property names would be a nice productivity boost.

Btw, a similar API is one of the planned features for JPA 2.0.

For more detail (and source or sample code above), see hibernate reference manual: Chapter 15. Criteria Queries



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.