-
1. Re: Framework: Counting query entities
chris1 Apr 16, 2007 11:29 PM (in response to chris1)Hey!
Bump :D
I cannot believe nobody else is currently using the great seam framework without state of the art pagination?
Best,
Chris -
2. Re: Framework: Counting query entities
cptnkirk Apr 17, 2007 2:43 AM (in response to chris1)Looks like a problem to me. As a work around try something like:
@Name("myQuery") public class MyQuery extends EntityQuery { protected String getCountEjbql() { return "select count(*) without fetch"; } public String getEjbql() { return "original query"; } }
Not as great as the components.xml solution, but should keep you functioning until this is sorted out.
Oh what the heck, you should be able to smack things around a bit. Maybe even even include some components.xml like this.<component name="someQuery" auto-create="true" class="x.y.MyQuery"> <property name="countEjbql">select count(*) no fetch</property> <property name="ejbql">original</property> </component> <component name="OtherQuery" auto-create="true" class="x.y.MyQuery"> <property name="countEjbql"></property> <property name="ejbql"></property> </component>
not sure if the countEjbql stuff has a public setter might need to add one. I guess in the end you have something like:public class PersonQuery extends EntityQuery { private String countEjbql; protected String getCountEjbql() { return countEjbql; } public void setCountEjbql(String query) { countEjbql = query; } }
I haven't tried any of this, but it sounds about right to me. Let me know. -
3. Re: Framework: Counting query entities
cptnkirk Apr 17, 2007 2:45 AM (in response to chris1)Oops, PersonQuery class in the last code block should be MyQuery.
-
4. Re: Framework: Counting query entities
chris1 Apr 17, 2007 8:07 AM (in response to chris1)Thanks Captain!
I'll do it your way. Of course a framework:entity-query in components.xml would have been nicer.
I believe you cannot automatically deviate a correct count query from any ejb/hql query in general, can we Gavin? If this is true we should think about a countEjbql attribute on framework:entity-query.
Makes sense?
Chris -
5. Re: Framework: Counting query entities
dsmith1 Apr 17, 2007 10:07 AM (in response to chris1)our solution to this was
@Override protected String getCountEjbql() { String countEjbql = super.getCountEjbql(); return countEjbql.replaceAll("join fetch", "join" ); }
-
6. Re: Framework: Counting query entities
chris1 Apr 17, 2007 10:26 AM (in response to chris1)mmh, interesting. This should work for my quoted query. But you cannot define the query within components.xml anymore, can you? I really love that feature because it saves me countless simple & stupig classes.
Chris -
7. Re: Framework: Counting query entities
cptnkirk Apr 17, 2007 11:12 AM (in response to chris1)Lol, should really not drink and make forum posts. :) A combination of dsmith's solution and my components.xml should give you what you're looking for. You only need 1 small class that you reuse in components.xml. You could even write your own namespace and have your own <myframework:entity-query> tag. But that's probably overkill, the <component...> syntax isn't that verbose.
Although I haven't tried it, you may even be able to use the class attribute on <framework:entity-query> to tell Seam to use your EntityQuery subclass. If so, great. You have plenty of options.
Based on the HQL, you'd think that Hibernate should be able to look at any digested query that has a single return and determine the correct count() syntax. Even eliminate unnecessary joins like the one you have here. Given how frequently this is used I think this would be a great convenience feature, especially for folks that use the Criteria APIs.