{"action":"created","issue":{"url":"https://api.github.com/repos/abstratt/cloudfier/issues/56","labels_url":"https://api.github.com/repos/abstratt/cloudfier/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/abstratt/cloudfier/issues/56/comments","events_url":"https://api.github.com/repos/abstratt/cloudfier/issues/56/events","html_url":"https://github.com/abstratt/cloudfier/issues/56","id":97356644,"number":56,"title":"generation of simple count queries","user":{"login":"abstratt","id":2187522,"avatar_url":"https://avatars.githubusercontent.com/u/2187522?v=3","gravatar_id":"","url":"https://api.github.com/users/abstratt","html_url":"https://github.com/abstratt","followers_url":"https://api.github.com/users/abstratt/followers","following_url":"https://api.github.com/users/abstratt/following{/other_user}","gists_url":"https://api.github.com/users/abstratt/gists{/gist_id}","starred_url":"https://api.github.com/users/abstratt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abstratt/subscriptions","organizations_url":"https://api.github.com/users/abstratt/orgs","repos_url":"https://api.github.com/users/abstratt/repos","events_url":"https://api.github.com/users/abstratt/events{/privacy}","received_events_url":"https://api.github.com/users/abstratt/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/abstratt/cloudfier/labels/generator","name":"generator","color":"c7def8"},{"url":"https://api.github.com/repos/abstratt/cloudfier/labels/jee","name":"jee","color":"0052cc"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-26T22:56:57Z","updated_at":"2015-09-03T20:14:50Z","closed_at":"2015-09-03T20:14:50Z","body":""},"comment":{"url":"https://api.github.com/repos/abstratt/cloudfier/issues/comments/137561825","html_url":"https://github.com/abstratt/cloudfier/issues/56#issuecomment-137561825","issue_url":"https://api.github.com/repos/abstratt/cloudfier/issues/56","id":137561825,"user":{"login":"abstratt","id":2187522,"avatar_url":"https://avatars.githubusercontent.com/u/2187522?v=3","gravatar_id":"","url":"https://api.github.com/users/abstratt","html_url":"https://github.com/abstratt","followers_url":"https://api.github.com/users/abstratt/followers","following_url":"https://api.github.com/users/abstratt/following{/other_user}","gists_url":"https://api.github.com/users/abstratt/gists{/gist_id}","starred_url":"https://api.github.com/users/abstratt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abstratt/subscriptions","organizations_url":"https://api.github.com/users/abstratt/orgs","repos_url":"https://api.github.com/users/abstratt/repos","events_url":"https://api.github.com/users/abstratt/events{/privacy}","received_events_url":"https://api.github.com/users/abstratt/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T20:14:50Z","updated_at":"2015-09-03T20:14:50Z","body":"This has been working for a bit:\r\n\r\n```\r\nclass City\r\n    attribute name : String;\r\n    attribute population : Integer;\r\n    attribute cityState : State;\r\n    static query citiesMorePopulousThan(threshold : Integer) : Integer;\r\n    begin\r\n        return City extent.select((c : City) : Boolean { c.population >= threshold } ).size();\r\n    end;\r\nend;\r\n```\r\n\r\nResults in:\r\n\r\n```\r\npublic long citiesMorePopulousThan(Long threshold) {\r\n        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();\r\n        CriteriaQuery<Long> cq = cb.createQuery(Long.class);\r\n        Root<City> city_ = cq.from(City.class);\r\n        return getEntityManager().createQuery(\r\n            cq.distinct(true).where(\r\n                cb.greaterThanOrEqualTo(\r\n                    city_.get(\"population\"),\r\n                    cb.parameter(Long.class, \"threshold\")\r\n                )\r\n            )\r\n            .select(cb.count(city_))\r\n        ).setParameter(\"threshold\", threshold).getResultList().stream().findAny().orElse(null);\r\n    }\r\n```"}}