1 Reply Latest reply on Feb 22, 2010 10:02 AM by blabno

    Dirty JPA instance

    ssamayoagt
      Hello.
      I guess this issue has already discused but here it comes:

      I have a Home component which edits some entity. User click "save" but persist() and update() methods are overriden to check some business validation against the instance, for exaple:

           @Override
           public String update() {
                Depto d = deptoXCodigo();
                if (d != null && !d.getDeptoId().equals(instance.getDeptoId())) {
                     facesMessages.addFromResourceBundle(Severity.ERROR,
                               "depto_cod_existe", d.getDeptoCodigo(), d.getDescripcion());
                     return null;
                }

                if (deptoSupRecursivo())
                     return null;

                return super.update();
           }

      When validation fails user is informed then he/she cancels the edit and backs to the entity query list page. Query is executed against database (I have hibernate.show_sql=true) but seems that instance is in the hibernate cache then is not lodaded/refreshed and shows the dirty entity not the one from database.

      entityManager().clear() when business validation leads to another problems.

      Please give me some ideas or best practices on how to resolve this.

      Thanks.

      Regards.