0 Replies Latest reply on Dec 16, 2007 11:26 AM by Alexey Borschenko

    unable to update entity in collection

    Alexey Borschenko Newbie

      Another odd thing with hibernate:

      using the code below I'm unable to update entity data but successfully may add new one to collection :

      /**
      * Writes qualification info into DB
      *
      * @param qualification object model to be updated
      * @return true if successfull
      * @throws Exception
      */
      public boolean saveQualification(UsersAcademicQualifications qualification) throws Exception {
      if (qualification != null) {

      usersAcademicQualificationsHome.setInstance(qualification);

      if (qualification.getId() != null && qualification.getId().trim().length() > 0) {
      usersAcademicQualificationsHome.update();
      }
      else {
      usersAcademicQualificationsHome.persist();
      }

      usersAcademicQualificationsHome.getEntityManager().flush();

      //updating related entities
      usersAcademicQualificationsHome.setId(qualification.getId());
      qualification = usersAcademicQualificationsHome.find();

      //adding new qualification to related Users object
      {
      qualification.getUsers().getUsersAcademicQualifications().add(qualification);
      usersFacade.saveUser(qualification.getUsers());
      }

      return true;
      }
      return false;
      }