0

I get an InvalidStateException when inserting an entity in Hibernate with JPA. I've learned that the exceptions originates from the ValidateEventListener class from Hibernate. It gets thrown but I have nowhere to catch it.

Does anyone know how I can catch this exception so I can log the invalidvalue?

@Override
public T create(T entity) {
    getEntityManager().persist(entity);
    return entity;
  }

When I surround the persist I can't catch the InvalidstateException. Its already gone.

wvp
  • 1,134
  • 5
  • 15
  • 28
  • Did you check earlier posts here? http://stackoverflow.com/questions/4067920/what-would-cause-an-hibernate-invalidstateexception – Germann Arlington Sep 12 '12 at 07:44
  • Yes I've seen it. But I can't seem to catch met exception when persisting. I've updated my post with code. – wvp Sep 12 '12 at 07:47
  • Do you mean that the exception is caught (and not rethrown) somewhere else (JPA?)? Than you can try to turn debug mode in both Hibernate and JPA to see if that will help and turn on SQL logging in Hibernate - it may be helpful too. – Germann Arlington Sep 12 '12 at 08:24
  • No the exception is thrown, I can see it in my logs. But I want the invalidvalues to be printed out to the log as well. So I need a place to catch it so I can log the invalidvalues and than just rethrow it. – wvp Sep 12 '12 at 08:27
  • The fact that you **CAN** see it in your logs means that it **WAS** caught and processed, otherwise the application would blow up. Look at the logs to check which method actually throws the exception, try to use interceptors to wrap your try/catch code around the call... – Germann Arlington Sep 13 '12 at 13:54

0 Answers0