@SuppressWarnings( { "ThrowableInstanceNeverThrown", "unchecked" })
public Object getSingleResult() {
try {
List result = query.list();
if ( result.size() == 0 ) {
throwPersistenceException( new NoResultException( "No entity found for query" ) );
}
else if ( result.size() > 1 ) {
Set uniqueResult = new HashSet( result );
if ( uniqueResult.size() > 1 ) {
throwPersistenceException( new NonUniqueResultException( "result returns " + uniqueResult.size() + " elements" ) );