[ https://issues.apache.org/jira/browse/XMLBEANS-473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13439567#comment-13439567 ]
Daniel Grönberg commented on XMLBEANS-473: ------------------------------------------ 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> Use this method will parse out the date from that String and return a Date: 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. > XML "dateTime" type issue with JDBC Control > ------------------------------------------- > > Key: XMLBEANS-473 > URL: https://issues.apache.org/jira/browse/XMLBEANS-473 > Project: XMLBeans > Issue Type: Bug > Components: XmlObject > Affects Versions: Version 2.2 > Reporter: Sunil Polineni > Labels: features > Attachments: jdbcTestWorkspace.rar > > > 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? -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@xmlbeans.apache.org For additional commands, e-mail: dev-h...@xmlbeans.apache.org