Issue Type: Improvement Improvement
Affects Versions: 4.1.9
Assignee: Unassigned
Components: core
Created: 13/Dec/12 11:36 PM
Description:

Criterion Interface should get a getter for the propertyName that is used in static Restriction class.
This would allow for easier dynamic Criteria creation including subqueries.

Following is a use case example:

I wrote a utility method that creates dynamic criteria's from given bean properties including subqueries if property names access child parameters.
Since this method is so usefull I never write criteria's manually anymore.

First a tree is created from a map of propertyName-values like following:
(In reality the value is of type Criterion.)

Filters:

foo.name=peter
foo.test.id=2
bar.value=xy

Tree:

-foo
--name=peter
--test
---id=2
-bar
--value=xy

Then dynamic criteria's are created.
To create this tree the property name is necessary to know.

Thats why the filter map I use is of type:

Map<String, Criterion> where the key value is the propertyName already used in the Criterion.

In real code this looks very ugly since I need to provide the propertyName multiple times. (In the Criterion creation and the Map key!)
Else I would have no access to the propertyName in my dynamic Criteria creation method.

Map<String, Criteron> filters = new HashMap<String, Criterion>();
filter.put("foo.bar.name", Restrictions.like("foo.bar.name", "peter");
filter.put("foo.test.id", Restrictions.eq("foo.test.id", 2);
filter.put("bar.value", Restrictions.ne("bar.value", "xy");

List<Class> data = HibernateUtils.createDetachedCriteria(Class, SessionFactory, filters).getExecutableCriteria(session).list();

Project: Hibernate ORM
Labels: hibernate criterion
Priority: Major Major
Reporter: Marco Janc
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira