Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-2560

[DataNucleus] Introduced findXxx(id) method throws EmptyResultDataAccessException instead of returning null when no data is found

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 1.1.4.RELEASE
    • Fix Version/s: 1.1.5.RELEASE
    • Component/s: PERSISTENCE
    • Labels:
      None
    • Environment:
      Database = DataNucleus

      Description

      The following script:

      domain.roo
      persistence setup --provider DATANUCLEUS --database GOOGLE_APP_ENGINE --applicationId myapp
      entity --class ~.server.domain.DomainObject --testAutomatically
      field string --fieldName displayName --notNull
      web gwt setup
      

      will generate this "find by ID" method:

      DomainObject_Roo_Entity.aj
      @Transactional
      public static DomainObject DomainObject.findDomainObject(Long id) {
          if (id == null) return null;
          try {
              return (DomainObject) entityManager().createQuery("SELECT o FROM DomainObject o WHERE o.id = :id").setParameter("id", id).getSingleResult();
          } catch (javax.persistence.NoResultException e) {
              return null;
          } 
      }

      If no row exists with that ID, JpaExceptionTranslatorAspect kicks in and translates the resulting javax.persistence.NoResultException into an org.springframework.dao.EmptyResultDataAccessException before it can be caught in the catch block, meaning that the finder throws the latter exception instead of returning null in that scenario.

      As evidence of this bug, the generated DomainObjectIntegrationTest.testRemove() method fails with an org.springframework.dao.EmptyResultDataAccessException (thrown from the final assert statement).

        Attachments

          Activity

            People

            Assignee:
            aswan Andrew Swan
            Reporter:
            nitzanv Nitzan Volman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: