Optimize AbstractProductQuery#getSingleResult

Also brings the method in line with the spec for some in-memory databases like HSQL.
This commit is contained in:
TomyLobo 2019-11-21 20:25:42 +01:00
parent c9a373c180
commit 6cf36acd53
1 changed files with 9 additions and 3 deletions

View File

@ -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() );