Author: dstephan
Date: 2008-06-22 19:07:56 -0400 (Sun, 22 Jun 2008)
New Revision: 14795
Modified:
entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java
Log:
JBPAPP-899 - Hibernate enitiymanager - getSingleResult() and fetch raise abusive
NonUniqueResultException - ref: EJB-263
Modified: entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java
===================================================================
---
entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java 2008-06-21
13:47:31 UTC (rev 14794)
+++
entitymanager/branches/v3_2_1_GA_CP/src/java/org/hibernate/ejb/QueryImpl.java 2008-06-22
23:07:56 UTC (rev 14795)
@@ -5,6 +5,8 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
import javax.persistence.FlushModeType;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
@@ -82,7 +84,13 @@
em.throwPersistenceException( new NoResultException( "No entity found for
query" ) );
}
else if ( result.size() > 1 ) {
- em.throwPersistenceException( new NonUniqueResultException( "result returns
" + result.size() + " elements") );
+ Set uniqueResult = new HashSet(result);
+ if ( uniqueResult.size() > 1 ) {
+ em.throwPersistenceException( new NonUniqueResultException( "result returns
" + uniqueResult.size() + " elements") );
+ }
+ else {
+ return uniqueResult.iterator().next();
+ }
}
else {
return result.get(0);
Show replies by date