ColdBox Criteria Builder, getting the Criteria.

Previously, using the old methods of using criteria search in Virtual Entity Service “criteriaQuery()” I was able to return the built-up criteria array and dynamically modify it for various reasons (faceted search, dynamic counts, etc). Screen shot of the dumped criteria array simplified: http://i.imgur.com/JuDXfut.png

I looked into the new Criteria Builder objects coldbox.system.orm.hibernate.BaseBuilder and by extension org.hibernate.impl.CriteriaImpl, but I’m unable to get the array of created criteria as before. I noticed BaseBuilder has the method getCriterias() but that always seems to return an empty array.

Can someone point me in the right direction?

What is it that you need to do with the array of restrictions? With the Criteria Builder DSL, you should be able to dynamically build queries.

Have you tried this and not had luck with what you want to accomplish, or are you just looking for a place to start with the Criteria Builder? If so, the wiki has a really nice introduction to it: http://wiki.coldbox.org/wiki/ORM:CriteriaBuilder.cfm

Ah of course I’ve looked over http://wiki.coldbox.org/wiki/ORM:CriteriaBuilder.cfm

I’ve used the array of criteria to do faceted search counts. For all search options, take the criteria array and append a new index, run the count query, repeat for all possible search options. Works really well.

Is coldbox.system.orm.hibernate.BaseBuilder getCriterias() method always supposed to return an empty array or is something wrong?

It doesn’t appear that getCriterias() does anything other than what you’re experiencing. In looking back through the evolution of this, it appears it is an unused holdover that should probably be removed to avoid confusion. At least I don’t see where it is being used, and all the history of commits that I see seem to indicate that it was used in code that was replaced back in 2012.

Nonetheless, the current implementation of Criteria Builder should still allow you to accomplish what you’re after. Using the CriteriaBuilder’s api, you can still append restrictions, do a count, add more restrictions, do another count, and so on.

Here’s a simple example, but I think it illustrates the point: