Optimize AbstractProductQuery#getSingleResult
Also brings the method in line with the spec for some in-memory databases like HSQL.
This commit is contained in:
parent
c9a373c180
commit
6cf36acd53
|
@ -1572,10 +1572,16 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
public R getSingleResult() {
|
||||
try {
|
||||
final List<R> list = list();
|
||||
if ( list.size() == 0 ) {
|
||||
switch ( list.size() ) {
|
||||
case 0:
|
||||
throw new NoResultException( "No entity found for query" );
|
||||
|
||||
case 1:
|
||||
return list.get( 0 );
|
||||
|
||||
default:
|
||||
throw new NonUniqueResultException( list.size() );
|
||||
}
|
||||
return uniqueElement( list );
|
||||
}
|
||||
catch ( HibernateException e ) {
|
||||
throw getExceptionConverter().convert( e, getLockOptions() );
|
||||
|
|
Loading…
Reference in New Issue