Created
March 16, 2011 14:47
-
-
Save olivermt/872596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, Integer> listDistinctGrossDepEnv() { | |
HibernateCriteriaBuilder builder = OutcropSection.createCriteria() | |
Collection results = builder.list { | |
// Not binding to a bean | |
resultTransformer(AliasToEntityMapResultTransformer.INSTANCE) | |
projections { | |
groupProperty("grossDepositionalEnvironment", "keyName") | |
depositionalEnvironment { | |
subEnvironment { | |
count("architecturalElement", "countValue") | |
} | |
} | |
} | |
} | |
// Transform the results. | |
Map<String, Integer> distinctMap = [:] | |
results.each { distinctMap.put it.keyName, it.countValue } | |
return distinctMap | |
} | |
class DepositionalSubEnvironment { | |
static hasMany= [architecturalElement:ArchitecturalElement] | |
} | |
Hibernate: | |
select | |
this_.gross_depositional_environment as y0_, | |
count(subenviron2_.id) as y1_ | |
from | |
outcrop_section this_ | |
left outer join | |
depositional_environment deposition1_ | |
on this_.id=deposition1_.section_id | |
left outer join | |
depositional_sub_environment subenviron2_ | |
on deposition1_.id=subenviron2_.depositional_environment_id | |
group by | |
this_.gross_depositional_environment | |
-------- | |
What i want to do: | |
For each of grossDepositionalEnvironment type (it's an enum constrained string) of Outcrop i want to go down to subEnvironment and count how many architectural elements there are. | |
There is supposed to be 2700 archi elements, but the query on top here added together ends up around 3-400 only. | |
What i suspect: We are counting how many subEnvironments have 1 or more archielement children. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment