[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2893?page=c...
]
Antony Stubbs commented on HHH-2893:
------------------------------------
P.s.
The test case for the exclusion of the group by for this criteria:
Criteria exclude =
s.createCriteria(Student.class).setProjection(Projections.projectionList().add(
Projections.max("studentNumber")).add(
Projections.groupProperty("name", true))
);
produces this sql:
select
max(this_.studentId) as y0_
from
Student this_
group by
this_.name
As opposed to this sql for inclusion:
select
max(this_.studentId) as y0_,
this_.name as y1_
from
Student this_
group by
this_.name
The default behaviour where you don't specify an option:
Criteria exclude =
s.createCriteria(Student.class).setProjection(Projections.projectionList().add(
Projections.max("studentNumber")).add(
Projections.groupProperty("name")
);
produces the same result as if you chose to not exclude it
select
max(this_.studentId) as y0_,
this_.name as y1_
from
Student this_
group by
this_.name
I have only tested this on the default db (hsqldb) as the test runner uses. This should
definitely be tested on the other databases as well. Do you have a process for doing
that?
Criteria api does not allow a groupProperty to _NOT_ be included in
the selected columns
----------------------------------------------------------------------------------------
Key: HHH-2893
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2893
Project: Hibernate3
Issue Type: Patch
Components: query-criteria
Affects Versions: 3.2.5
Environment: n/a
Reporter: Antony Stubbs
Attachments: HHH2893-test.patch, hibernate criterion patch.patch
Original Estimate: 2 hours
Remaining Estimate: 2 hours
When adding a Projections.groupProperty("prop") to a criteria, the property is
added to both the GROUP BY and SELECT parts of the generated SQL query. This is a major
problem for using the criteria API for complex subselects that require aggregating by a
column while grouping by another column.
There is presently no way in the criteria API to group by a column and have it _ONLY_ in
the GROUP BY clause.
i.e.
currently Projections.groupProperty("propOne") causes:
SELECT propOne, MAX(propTwo) FROM table GROUP BY prop
desired option is to have
SELECT MAX(propTwo) FROM table GROUP BY prop
There have been several people talking about this, but there appears to have been 'no
comment'.
http://forum.hibernate.org/viewtopic.php?t=939071&highlight=values+gr...
http://forum.hibernate.org/viewtopic.php?t=950803&highlight=groupprop...
http://forum.hibernate.org/viewtopic.php?t=964512&highlight=groupprop...
http://forum.hibernate.org/viewtopic.php?t=957671&highlight=groupprop...
http://forum.hibernate.org/viewtopic.php?p=2317841#2317841
http://forum.hibernate.org/viewtopic.php?t=961617&highlight=groupprop...
Find a 1st cut patch on it's way - I'm just itching my scratch now...
Great work on Hibernate guys!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira