Robson Amaral

Robson Amaral

  • NA
  • 132
  • 17.3k

NHibernate.NonUniqueResultException: List

Apr 11 2018 1:31 PM

I have the following problem, when compiling my application, it returns the following error:
 
 
NHibernate.NonUniqueResultException: query did not return a unique result: 2    
in NHibernate.Impl.AbstractQueryImpl.UniqueElement (IList list)    
in NHibernate.Impl.CriteriaImpl.UniqueResult ()    
in NHibernate.Impl.CriteriaImpl.UniqueResult [T] ()    
in SDPJDomain.DataAccess.ProcessOID.ConfirmProcessor (String numProcess) 
in D: \ SVN \ SDP \ SDPJ \ branches \ SDPJ-V3.0.0 \ SDPJDomain \ 
DataAccess \ ProcessData.cs: line 111

  1. public static Process ConsultforNProcessER(string numProcess)  
  2.         {  
  3.             ISession session = NhibernateHelper.SessionCurrent;  
  4.             Process process;  
  5.   
  6.             try  
  7.             {  
  8.                 process = new Process();  
  9.   
  10.                 ICriteria criteria = session.CreateCriteria(process.GetType());  
  11.                 //criteria.Add(NHibernate.Criterion.Expression.Sql("replace(replace(replace(Num_Proc_Judicial, '.'), '-'), '/') = replace(replace(replace(?, '.'), '-'), '/')", numProcess, NHibernateUtil.String));                  
  12.                 criteria.Add(NHibernate.Criterion.Expression.Sql("regexp_replace(Num_Proc_Judicial || '/','[[:punct:]]','') = regexp_replace(? || '/','[[:punct:]]','')", numProcess, NHibernateUtil.String));  
  13.                 return criteria.UniqueResult<Process>();  
  14.             }  
  15.             catch (Exception e)  
  16.             {  
  17.                 throw new Exception(e.ToString());  
  18.             }  
  19.         }  

Line 111 is in return criteria.UniqueResult <Process> ();
 
Does anybody know how to solve this?