XMLBeans
  1. XMLBeans
  2. XMLBEANS-473

XML "dateTime" type issue with JDBC Control

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: Version 2.2
    • Fix Version/s: None
    • Component/s: XmlObject
    • Labels:

      Description

      This issue happens when you define a database control method which SELECTs data and returns an XML Bean document. If one of the selected columns in your XML schema is of type "dateTime", then the XML text that is returned is missing the required "T" time separator character. Therefore, any subsequent attempts to call the getters on the resulting XML Bean document object (which normally should return java.util.Calendar objects) results in exceptions.

      @JdbcControl.SQL(statement="SELECT THE_ID as \"theId\", THE_DATE as \"theDate\" FROM JDBC_TEST WHERE THE_ID =

      {id}

      ")
      XJdbcTestDocument runJdbcTest(String id) throws SQLException;

      XJdbcTestDocument is generated from the below xml file
      =========================================
      <schema
      xmlns="http://www.w3.org/2001/XMLSchema"
      targetNamespace="java:///JdbcTestXMLSchema"
      xmlns:tns="http://www.example.org/JdbcTestXMLSchema"
      elementFormDefault="qualified">

      <element name="XJdbcTest">
      <complexType>
      <choice maxOccurs="unbounded">
      <element name="XJdbcTestRow">
      <complexType>
      <sequence>
      <element name="theId" type="string" minOccurs="0"/>
      <element name="theDate" type="dateTime" minOccurs="0" nillable="true"/>
      </sequence>
      </complexType>
      </element>
      </choice>
      </complexType>
      </element>
      </schema>
      =============================================
      The <xml-fragment>1998-05-31 00:00:00.0</xml-fragment> is missing "T" it should be <xml-fragment>1998-05-31T00:00:00.0</xml-fragment> when this is being returned by a JDB Control and getting below exception

      javax.el.ELException: org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid date value: 1998-05-31 00:00:00.0
      at javax.el.BeanELResolver.getValue(BeanELResolver.java:266)
      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:143)
      at com.sun.el.parser.AstValue.getValue(AstValue.java:118)
      at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
      at weblogic.servlet.jsp.ELHelper.evaluate(ELHelper.java:32)
      at jsp_servlet._jdbcresults._jspService(_jdbcresults.java:205)

      I think When JDBC Control maps result set to XML, it by default uses SQL object's toString() method to convert from SQL object to String.

      To override/customize this behavior we can use ResultSetMapper
      http://beehive.apache.org/docs/1.0.1/system-controls/jdbc/apidocs/javadoc/org/apache/beehive/controls/system/jdbc/ResultSetMapper.html
      but this requires some good amount change in the code.

      Can you please advise whether if there is any other alternative?

        Activity

        Sunil Polineni created issue -
        Hide
        Kalyan Valluri added a comment -

        Hi Team,

        I am also noticing the same issue.Any hints when this will be fixed?

        Thanks,
        Kalyan

        Show
        Kalyan Valluri added a comment - Hi Team, I am also noticing the same issue.Any hints when this will be fixed? Thanks, Kalyan
        Hide
        Sunil Polineni added a comment -

        Any Update on this highly appreciated.

        Best Regards,
        Sunil

        Show
        Sunil Polineni added a comment - Any Update on this highly appreciated. Best Regards, Sunil
        Hide
        Jerry Sy added a comment -

        Can you provide a reproducer for this issue?

        Thanks
        Jerry

        Show
        Jerry Sy added a comment - Can you provide a reproducer for this issue? Thanks Jerry
        Hide
        Sunil Polineni added a comment -

        1. Run the following statements on your own database instance:
        CREATE TABLE JDBC_TEST
        (
        THE_ID VARCHAR2(30) NOT NULL,
        THE_DATE DATE NULL
        );
        insert into jdbc_test (the_id, the_date) values ('1234', sysdate);
        insert into jdbc_test (the_id, the_date) values ('5678', null);

        2. Create a data source on your own WebLogic server that references the database where you ran the above creation/inserts.

        3. Modify my test code contained within the attached jdbcTestWorkspace.rar (\jdbcTest\jdbcTestApp\src\jdbcTestControl.java) to reference the data source name you created above rather than "cgDataSource".
        @JdbcControl.ConnectionDataSource(jndiName = "<your-data-source-name")

        4. Compile, deploy, and run my test code (\jdbcTest\jdbcTestApp\src\Controller.java). Click on the various links defined on my index.jsp to observe the exceptions produced. You can use either Oracle(BEA's) or Apache's JdbcControl using the import found within jdbcTestControl.java. The same exceptions/bugs can be observed either way.

        will upload the project

        Show
        Sunil Polineni added a comment - 1. Run the following statements on your own database instance: CREATE TABLE JDBC_TEST ( THE_ID VARCHAR2(30) NOT NULL, THE_DATE DATE NULL ); insert into jdbc_test (the_id, the_date) values ('1234', sysdate); insert into jdbc_test (the_id, the_date) values ('5678', null); 2. Create a data source on your own WebLogic server that references the database where you ran the above creation/inserts. 3. Modify my test code contained within the attached jdbcTestWorkspace.rar (\jdbcTest\jdbcTestApp\src\jdbcTestControl.java) to reference the data source name you created above rather than "cgDataSource". @JdbcControl.ConnectionDataSource(jndiName = "<your-data-source-name") 4. Compile, deploy, and run my test code (\jdbcTest\jdbcTestApp\src\Controller.java). Click on the various links defined on my index.jsp to observe the exceptions produced. You can use either Oracle(BEA's) or Apache's JdbcControl using the import found within jdbcTestControl.java. The same exceptions/bugs can be observed either way. will upload the project
        Hide
        Sunil Polineni added a comment -

        Test Case to reproduce the issue

        Show
        Sunil Polineni added a comment - Test Case to reproduce the issue
        Sunil Polineni made changes -
        Field Original Value New Value
        Attachment jdbcTestWorkspace.rar [ 12513507 ]
        Hide
        Jerry Sy added a comment -

        Thanks Sunil.

        Can you update the oracle bug with the same info so it can be tracked internally as well? I will investigate this from the oracle bug first.

        Thanks,
        Jerry

        Show
        Jerry Sy added a comment - Thanks Sunil. Can you update the oracle bug with the same info so it can be tracked internally as well? I will investigate this from the oracle bug first. Thanks, Jerry
        Hide
        Daniel Grönberg added a comment - - edited

        Here is a possible workaround until it is fixed. For you, who like me, can't wait for this to be solved and are stuck on xmlbeans 2.2:

        Lets say that getValue is the method of the XMLObject that is supposed to give you a Calendar but throws XmlValueOutOfRangeException instead. What I found is that xgetValue successfully returns an XmlDateTime. Trying to do getCalendar will throw the same exception but toString will successfully give you a String representation which looks something like this: <xml-fragment>2012-11-01 00:00:00.0</xml-fragment>

        See my example below how to solev this:

        Calendar cal;

        try

        { cal = xmlObj.getValue(); }

        catch (org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException ex)

        { /** * Due to a bug in xmlbeans this exception is thrown when trying to get a date. * See https://issues.apache.org/jira/browse/XMLBEANS-473 This workaround reads the xml representation * instead and parses out the date. */ Date dateFromXmlString = convertFaultyXMLDateStringToDate(xmlObject.xgetValue().toString()); cal= Calendar.getInstance(); cal.setTime(dateFromXmlString); }

        private Date convertFaultyXMLDateStringToDate(String xmlString) throws ParseException {
        Pattern datePattern = Pattern.compile("[0-9][0-9][0-9]* [0-9]:[0-9]:[0-9].[0-9]");
        Matcher dateMatcher;

        dateMatcher = datePattern.matcher(xmlString);
        if (dateMatcher.find())

        { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); return sdf.parse(dateMatcher.group(0)); }

        else

        { //Handle no match }

        }

        Something to use until it's fixed.

        Show
        Daniel Grönberg added a comment - - edited Here is a possible workaround until it is fixed. For you, who like me, can't wait for this to be solved and are stuck on xmlbeans 2.2: Lets say that getValue is the method of the XMLObject that is supposed to give you a Calendar but throws XmlValueOutOfRangeException instead. What I found is that xgetValue successfully returns an XmlDateTime. Trying to do getCalendar will throw the same exception but toString will successfully give you a String representation which looks something like this: <xml-fragment>2012-11-01 00:00:00.0</xml-fragment> See my example below how to solev this: Calendar cal; try { cal = xmlObj.getValue(); } catch (org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException ex) { /** * Due to a bug in xmlbeans this exception is thrown when trying to get a date. * See https://issues.apache.org/jira/browse/XMLBEANS-473 This workaround reads the xml representation * instead and parses out the date. */ Date dateFromXmlString = convertFaultyXMLDateStringToDate(xmlObject.xgetValue().toString()); cal= Calendar.getInstance(); cal.setTime(dateFromXmlString); } private Date convertFaultyXMLDateStringToDate(String xmlString) throws ParseException { Pattern datePattern = Pattern.compile(" [0-9] [0-9] [0-9] * [0-9] : [0-9] : [0-9] . [0-9] "); Matcher dateMatcher; dateMatcher = datePattern.matcher(xmlString); if (dateMatcher.find()) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); return sdf.parse(dateMatcher.group(0)); } else { //Handle no match } } Something to use until it's fixed.

          People

          • Assignee:
            Unassigned
            Reporter:
            Sunil Polineni
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Development