1 Reply Latest reply on Feb 5, 2009 7:04 PM by Matti Aarnio

    Get hibernate error details into EntityHome's persist() function.

    Matti Aarnio Newbie

      Our application has complicated constraint management in database triggers/script language, and this works fine so that in actual operational program we can get database produced EXCEPTION messages to calling application.


      In Customer Care application written with Seam (2.0.2), we get big backtrace on log, and entirely uninformative error status: Unexpected error, please try again on web.



      A shortened version of relevant EntityHome(T) persist() function is:


          public String persist() {
              try {
                  return super.persist();
              } catch ( .... )
                 ... System.err.println(...);
              }
              return "error";
          }
      



      What my tests show is that no catch happens here, rather somewhere deep inside Hibernate:



      2009-02-05 18:13:19,004 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: null
      2009-02-05 18:13:19,004 ERROR [org.hibernate.util.JDBCExceptionReporter] Batch entry 0 insert into public.mobile_user (state, create d_by, modified_by, msisdn, imsi, custom_id, id) values (1, admin, admin, 0400285469, NULL, , 11) was aborted.  Call getNextException  to see the cause.
      2009-02-05 18:13:19,004 WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 0, SQLState: P0001
      2009-02-05 18:13:19,004 ERROR [org.hibernate.util.JDBCExceptionReporter] ERROR: This new MSISDN already exists in ACTIVE state in MOBILE_USER table. Insert denied.
      2009-02-05 18:13:19,008 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] Could not synchronize database state with session
      org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
              at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
              at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
              at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
              at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
              at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)
              at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:90)
              at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:48)
              at fi.methics.kiuru.management.MobileUserHome.persist(MobileUserHome.java:198)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      .........
      2009-02-05 19:43:56,930 ERROR [STDERR] MobileUserHome.persist() caught exception: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
      2009-02-05 19:43:56,930 ERROR [STDERR] javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
      .........
      



      So, How do I get the REAL message out to my application user ?
      (And remove the backtrace from logs.)