title: More than one row with the given identifier was found: 1, for class: com.model.Diagnosis
body: <p>Below is the model, service implementation and the error trace of my code. </p>
  
  <p>Model class:</p>
  
  <pre><code>@Entity
  @Table(name = "ph_diagnosis_history")
  @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id",scope=Diagnosis.class)
  public class Diagnosis extends AbstractEntity {
      @Column(name = "diagnosis_notes", length=255)
      @Length(max = 255, message = IprProp.MAX_LEN_255_MSG)
      private String diagnosisNote;
  
      @Enumerated(EnumType.STRING)
      private DiagnosisTypeEnum type;
  
      @Temporal(TemporalType.DATE)
      @Column(name = "diagnosis_date")
      @JsonSerialize(using = JsonDateSerializer.class)
      private Date diagnosisDate;
  
      @ManyToOne
      @JoinColumn(name = "patient_chart_id")
      private PatientChart patientChart;
  
      public String getDiagnosisNote() {
          return diagnosisNote;
      }
  
      public void setDiagnosisNote(String diagnosisNote) {
          this.diagnosisNote = diagnosisNote;
      }
  
      public DiagnosisTypeEnum getType() {
          return type;
      }
  
      public void setType(DiagnosisTypeEnum type) {
          this.type = type;
      }
  
      public Date getDiagnosisDate() {
          return diagnosisDate;
      }
  
      public void setDiagnosisDate(Date diagnosisDate) {
          this.diagnosisDate = diagnosisDate;
      }
  
      public PatientChart getPatientChart() {
          return patientChart;
      }
  
      public void setPatientChart(PatientChart patientChart) {
          this.patientChart = patientChart;
      }
  }
  </code></pre>
  
  <p>My service:</p>
  
  <pre><code>public Diagnosis updateDiagnosis(IPRDTO clientDto, Long userId,
          Long patientChartId, DiagnosisDTO diagnosisDTO, Long diagnosisId) throws Exception {
      Diagnosis diagnosis = diagnosisRepository.findOne(diagnosisId);
      if (diagnosis!=null){
          if(diagnosis.getType().equals(DiagnosisTypeEnum.WORKING)){
              BeanCopyUtil.copyProperties(diagnosisDTO, diagnosis, true);
              return this.diagnosisRepository.saveAndFlush(diagnosis);
          }
          else{
              throw new BusinessException("updateDiagnosisValidation"); 
          }
      }
      throw new BusinessException("noDiagnosis"); 
  }
  </code></pre>
  
  <p>My stack trace:</p>
  
  <pre><code> [2014-09-08 11:34:08,148] INFO  com.zurelsoft.ipr.service.IDiagnosisService- Logged In User Id [1]:Started  updateDiagnosis
      diagnosis id 2
      [2014-09-08 11:34:08,969] INFO  org.hibernate.event.internal.DefaultLoadEventListener- HHH000327: Error performing load command : org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: com.zurelsoft.ipr.model.Diagnosis
      [2014-09-08 11:34:09,001] ERROR com.zurelsoft.ipr.service.IDiagnosisService- Logged In User Id [1]:Error Occurred updateDiagnosis
      org.springframework.orm.jpa.JpaSystemException: org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: com.zurelsoft.ipr.model.Diagnosis; nested exception is javax.persistence.PersistenceException: org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: com.zurelsoft.ipr.model.Diagnosis
      [2014-09-08 11:34:09,006] ERROR com.zurelsoft.ipr.client.DiagnosisWebService- org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:321)
      org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:403)
      org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:58)
      org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
      org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:163)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      com.sun.proxy.$Proxy85.findOne(Unknown Source)
      com.zurelsoft.ipr.service.impl.DiagnosisServiceImpl.updateDiagnosis(DiagnosisServiceImpl.java:76)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:51)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:51)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:55)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      com.sun.proxy.$Proxy86.updateDiagnosis(Unknown Source)
      com.zurelsoft.ipr.client.DiagnosisWebService.updateDiagnosis(DiagnosisWebService.java:98)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      java.lang.reflect.Method.invoke(Unknown Source)
      org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
      org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:849)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
      org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>I get this HibernateException in this line alhough my table has now two rows with the same id.</p>
  
  <pre><code>Diagnosis diagnosis = diagnosisRepository.findOne(diagnosisId);
  </code></pre>
  
  <p>Please anyone help me with my mistake. What can be probable error in my code.</p>