[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5056) Criteria API with ProjectionList and Unique result
Ahmed Ali Elsayed Ali Soliman (JIRA)
noreply at atlassian.com
Thu Feb 24 05:53:08 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5056?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=40071#action_40071 ]
Ahmed Ali Elsayed Ali Soliman commented on HHH-5056:
----------------------------------------------------
i made a debug in hibernate3.6.1 source code and i found the problem
in class org.hibernate.loader.hql.QueryLoader in function getResultList
protected List getResultList(List results, ResultTransformer resultTransformer) throws QueryException {
// meant to handle dynamic instantiation queries...
HolderInstantiator holderInstantiator = buildHolderInstantiator( resultTransformer );
if ( holderInstantiator.isRequired() ) {
for ( int i = 0; i < results.size(); i++ ) {
Object[] row = ( Object[] ) results.get( i );
Object result = holderInstantiator.instantiate(row);
results.set( i, result );
}
if ( !hasSelectNew() && resultTransformer != null ) {
return resultTransformer.transformList(results);
}
else {
return results;
}
}
else {
return results;
}
}
in the for loop there is a function Object result = holderInstantiator.instantiate(row); this function return tha latest selected column then after finishing the for statement it go to resultTransformer.transformList(results); which check the uniqueness between the last columns that i add to result
my opinion: you can solve it with one of the two ways
1- add a select distinct when you make the SQL statement from the first
2- remove the for loop then make resultTransformer.transformList(results); do the checks of distinct by public List transformList(List list) {
List result = new ArrayList( list.size() );
Set distinct = new HashSet();
for ( int i = 0; i < list.size(); i++ ) {
Object entity = list.get( i );
if ( distinct.add( new Identity( entity ) ) ) {
result.add( entity );
}
}
if ( log.isDebugEnabled() ) {
log.debug(
"transformed: " +
list.size() + " rows to: " +
result.size() + " distinct results"
);
}
return result;
}
which you will change it to check the identity of the row array (Object[])
please this is an important bug (my project is a very large scale that working for 3 Ports in my country) i can't migrate from hibernate 3.3.2 to hibernate 3.6.1 because of this problem
thanks.
> Criteria API with ProjectionList and Unique result
> --------------------------------------------------
>
> Key: HHH-5056
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5056
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.5.0-CR-2
> Environment: Hibernate 3.3.2, Oracel 11g
> Reporter: Ahmed Ali Elsayed Ali Soliman
> Assignee: Gail Badner
> Priority: Critical
>
> when you make a select statement with Criteria API & use ProjectionList to retrieve some columns then use the unique result
> make at least 2 projection list (2 columns or more)
> ProjectionList projectionList = Projections.projectionList() .add(Projections.property("ColumnA")) .add(Projections.property("ColumnB"));
> criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
> the result must be retrieved in 2 dimensional array of Object(Object[][])
> but the result are one dimensional array with one column only.
> Note:- when you remove the unique result it works fine but when you add it, it make this behavior.
--
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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list