String hql =
"select departmentPO from EmployePO as employePO join employePO.departmentPO as departmentPO "+
"where employePO.employeName like '%Jason%'"+
"order by departmentPO.deptId";
department table in database:
deptId deptName
d001 Java Team
d002 .net Team
employe table in database:
employeId employeName deptId
e001 Jason Lian d001
e002 Jason Tang d001
e003 Jason Yu d002
there are two results of query.list(): d001 , d001 and d002
how can I get a distinct results like d001 and d002?
select but when I use "select distinct departmentPO......",Hibernate reports a error:
Caused by: java.sql.SQLException: The text, ntext, or image data type cannot be selected as DISTINCT. Severity 16, State 3, Procedure 'JAVASERVER2 null', Line 1 at weblogic.jdbc.mssqlserver4.TdsStatement.processWarning(TdsStatement.java:1193) at weblogic.jdbc.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.java:1104) at weblogic.jdbc.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.java:771) at weblogic.jdbc.mssqlserver4.TdsStatement.execute(TdsStatement.java:210) at weblogic.jdbc.mssqlserver4.TdsStatement.executeQuery(TdsStatement.java:54) at weblogic.jdbc.mssqlserver4.TdsStatement.executeQuery(TdsStatement.java:1439) at weblogic.jdbc.wrapper.PreparedStatement.executeQuery(PreparedStatement.java:80) at weblogic.jdbc.rmi.internal.PreparedStatementImpl_weblogic_jdbc_wrapper_PreparedStatement_weblogic_jdbc_mssqlserver4_TdsPreparedStatement.executeQuery(Unknown Source) at weblogic.jdbc.rmi.internal.PreparedStatementImpl_weblogic_jdbc_wrapper_PreparedStatement_weblogic_jdbc_mssqlserver4_TdsPreparedStatement_WLSkel.invoke(Unknown Source) at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:407) at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:356) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:353) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:123) at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:351) at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)
I don't want to use like new HashSet(query.list()),because I want to sort by deptId.
I also don't want to use like
ArrayList result = new ArrayList();
for (Iterator it = query.list().iterator();it.hasNext();) {
Object object = it.next();
if (!result.contains(object)) {
result.add(object);
}
}
return result;
because I want to count the total number of query result
thanks.
|