Uploaded image for project: 'Olingo'
  1. Olingo
  2. OLINGO-50 Exceptions are not throw
  3. OLINGO-55

Enable JPA Processor to throw detail errors

    XMLWordPrintableJSON

Details

    • Sub-task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • V2 1.1.0
    • V2 1.1.0
    • odata2-jpa
    • None

    Description

      OData2 JPA Processor throws non detail error messages like

      "OData - JPA Runtime: JPA create request is not correct"

      To know the real cause for such errors ODataErrorCallBack interface needs to be implemented by respective service factory implementation. To enable quick start to the service development and considering minimal coding to enable JPA models as OData services; A default error call back implementation for OData2 JPA Processor library will be implemented. The call back can be registered by calling the protected method setDetailErrors(true). The method is part of ODataJPAServiceFactory class.

      An Example Service Factory Implementation

      public class JPAReferenceServiceFactory extends ODataJPAServiceFactory {

      private static final String PUNIT_NAME = "salesorderprocessing";
      private static final String MAPPING_MODEL = "SalesOrderProcessingMappingModel.xml";
      private static final String CONFIG = "Configuration";
      private static final String SHOW_DETAIL_ERROR = "showdetailerror";

      @Override
      public ODataJPAContext initializeODataJPAContext()
      throws ODataJPARuntimeException

      { ODataJPAContext oDataJPAContext = getODataJPAContext(); oDataJPAContext.setEntityManagerFactory(JPAEntityManagerFactory.getEntityManagerFactory(PUNIT_NAME)); oDataJPAContext.setPersistenceUnitName(PUNIT_NAME); oDataJPAContext.setJPAEdmMappingModel(MAPPING_MODEL); oDataJPAContext .setJPAEdmExtension((JPAEdmExtension) new SalesOrderProcessingExtension()); setErrorLevel(); // Based on parameters from Configuration file set the error level to detail or no detail return oDataJPAContext; }

      private void setErrorLevel()

      { ResourceBundle config = ResourceBundle.getBundle(CONFIG); boolean error = Boolean.parseBoolean((String) config.getObject(SHOW_DETAIL_ERROR)); setDetailErrors(error); }

      }

      If error level is set to detail, following is the format for the Error (Example based on Eclipselink)
      {
      error: {
      code: null
      message: {
      lang: "en"
      value: ""OData - JPA Runtime: JPA create request is not correct""
      }-
      innererror: "class javax.persistence.RollbackException : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: java.sql.SQLException: Violation of unique constraint SYS_PK_47: duplicate value(s) for column(s) SO_ID in statement [INSERT INTO T_SALESORDERHEADER (SO_ID, BUYER_ID, BUYER_NAME, CREATIONDATE, CURRENCY_CODE, DELIVERY_STATUS, GROSSAMOUNT, LONG_TEXT, NETAMOUNT, SHORT_TEXT, STATUS, CITY, COUNTRY, HOUSE_NUMBER, STREET_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] Error Code: -104 Call: INSERT INTO T_SALESORDERHEADER (SO_ID, BUYER_ID, BUYER_NAME, CREATIONDATE, CURRENCY_CODE, DELIVERY_STATUS, GROSSAMOUNT, LONG_TEXT, NETAMOUNT, SHORT_TEXT, STATUS, CITY, COUNTRY, HOUSE_NUMBER, STREET_NAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) bind => [2, 2, null, null, null, null, 0.0, null, 0.0, null, null, Chennai, null, 0, null] Query: InsertObjectQuery(org.apache.olingo.odata2.jpa.processor.ref.model.SalesOrderHeader@59729bd9)"
      }-
      }

      Attachments

        Issue Links

          Activity

            People

              chandan.v.a Chandan V.A
              chandan.v.a Chandan V.A
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: