tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Quintin Beukes <quin...@skywalk.co.za>
Subject Re: A Bug in OpenEJB?
Date Fri, 11 Sep 2009 08:04:13 GMT
I built a test case to prove the bug:
    package org.apache.openejb.jee.jpa.unit;

    import java.util.List;

    public class Test
    {
      public static void main(String[] args) throws Exception
      {
        Persistence persistence =
JaxbPersistenceFactory.getPersistence(Test.class.getResource("/persistence.xml"));
        Properties propertiesE =
persistence.getPersistenceUnit().get(0).getProperties();
        List<Property> properties = propertiesE.getProperty();
        for (Property prop : properties)
        {
          System.out.println("Prop: " + prop.getName() + " = " +
prop.getValue());
        }
      }
    }

Running this with this unit:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="KMSPlatform-PU" transaction-type="JTA">
        <properties>
          <property name="non-null-value" value="create-drop"/>
          <property name="null-value"/>
        </properties>
      </persistence-unit>
    </persistence>


Gives the following output:
    Prop: non-null-value = create-drop
    Prop: null-value = null

I got it to validate by adding the following code. When I do then it
only works if the value property is present. In other cases it gives
the exception the follows the code. for this to work you would have to
ship the XMLSchema file, which I know isn't ideal. I'm actually
confused as to why it doesn't use the annotations. But I know that the
Unmarshaller specifically says that validation is disabled if the
Schema object is null. So perhaps one needs to create a special schema
class instance, which constructs itself from the annotations?

Code to enable validation. Schema file from:
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd
            try
            {
              SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              Schema schema =
schemaFactory.newSchema(JaxbPersistenceFactory.class.getResource("/persistence_1_0.xsd"));
              u.setSchema(schema);
            }
            catch (SAXException e)
            {
            }

Exception:
Exception in thread "main" javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException: cvc-complex-type.4: Attribute 'value'
must appear on element 'property'.]
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:481)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:199)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:168)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:120)
        at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:103)
        at org.apache.openejb.jee.jpa.unit.JaxbPersistenceFactory.getPersistence(JaxbPersistenceFactory.java:82)
        at org.apache.openejb.jee.jpa.unit.Test.main(Test.java:9)
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.4:
Attribute 'value' must appear on element 'property'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(XMLSchemaValidator.java:410)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3165)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.addDefaultAttributes(XMLSchemaValidator.java:2859)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2041)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:685)
        at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:549)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:73)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.SAXConnector.startElement(SAXConnector.java:101)
        at org.xml.sax.helpers.XMLFilterImpl.startElement(XMLFilterImpl.java:527)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:501)
        at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:179)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:377)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2747)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
        at org.xml.sax.helpers.XMLFilterImpl.parse(XMLFilterImpl.java:333)
        at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:195)
        ... 5 more

Quintin

On Thu, Sep 10, 2009 at 11:35 PM, David Blevins <david.blevins@visi.com> wrote:
> This is strange as the parsing is done by JAXB and the related class looks
> setup correctly:
>
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "")
> public class Property {
>
>    @XmlAttribute(required = true)
>    protected String name;
>    @XmlAttribute(required = true)
>    protected String value;
>
> It should complain that you don't have the required attribute.
>
> -David
>
> On Sep 8, 2009, at 6:42 AM, Quintin Beukes wrote:
>
>> Hey,
>>
>> I can reproduce it everytime. All I have to do is leave out the value
>> attribute.
>>
>> Q
>>
>> On Tue, Sep 8, 2009 at 2:06 PM, Jean-Louis MONTEIRO
>> <jean-louis.monteiro@atosorigin.com> wrote:
>>>
>>> Hi Quintin,
>>>
>>> The specification only supports the second form.
>>> Here is an extract from the specification:
>>>                    <xsd:complexType>
>>>                       <xsd:attribute name="name" type="xsd:string"
>>>                                      use="required"/>
>>>                       <xsd:attribute name="value" type="xsd:string"
>>>                                      use="required"/>
>>>                     </xsd:complexType>
>>>
>>>
>>> Q Beukes wrote:
>>>>
>>>> I got the first one from an example. Can't recall where though, is it
>>>> incorrect? If I think about it I've always used the 2nd form.
>>>>
>>> Please, if you find it again, let us know so we can fix it.
>>>
>>> Thanks in advance.
>>> Jean-Louis
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Fwd%3A-A-Bug-in-OpenEJB--tp25313066p25344885.html
>>> Sent from the OpenEJB User mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>>
>> --
>> Quintin Beukes
>>
>
>



-- 
Quintin Beukes

Mime
View raw message