0 Replies Latest reply on Feb 13, 2006 5:52 PM by javatwo

    DB(hibernate) exception, detached entity usable?

    javatwo

      A web application using UserTransaction with Hibernate and JBoss EJB.

      When a user try to delete an entity using em.remove(detachedEntity), then commit transaction, but a Hibernate exception raised: reference constraints violated. In this case, the detached entity is still being hold by JSF backing bean, and user can edit it. When user apply the change using em.merge(), incorrect behavior occured. Either saying the detached entity is stale, or creating duplicate entity, or WrongClassException.

      Is there a way to detect reference violation before transaction commit to avoid DB exception?
      In case of DB(hibernate) exception, Is the detached entity re-usable? Is there a way to make it re-usable?

      If making a copy of the detached entity and giving the copy to user for editing, user can keep the change after hibernate exception. But deep copy is expensive. There are many types of entities, and implementation of deep copies is not trivial. I am looking for a way to keep detached entities usable even after Hibernate exception raised. Is there a way?

      Any idea/help are appreciated.
      Thanks in advance.