Issue Details (XML | Word | Printable)

Key: NUCRDBMS-657
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: No Testcase No Testcase
Assignee: Unassigned
Reporter: Chris Colman
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

Metadata class cast error when using datastore-identity/sequence strategy with Oracle

Created: 27/Mar/13 05:14 AM   Updated: 06/Apr/13 10:00 AM   Resolved: 27/Mar/13 09:24 AM
Component/s: None
Affects Version/s: 3.2.0.m4
Fix Version/s: None

Environment:
Windows
Oracle XE


 Description  « Hide
I encouter the following exception when setting up a class to use 'sequence' stategy for datastore identity.

    <class name="ms" detachable="true" persistence-modifier="persistence-capable" table="SS_GB_MESSAGE">
<datastore-identity strategy="sequence" sequence="ms"/>
        <inheritance strategy="new-table">
            <discriminator strategy="value-map" indexed="true" value="356572764">
                <column name="classid" jdbc-type="INTEGER" />
            </discriminator>
        </inheritance>
        <version strategy="version-number" column="VERSION" />
        <field name="n1" indexed="true">
        </field>
        <field name="n2">
        </field>
        <field name="n3">
        </field>

        <field name="bits" persistence-modifier="persistent" mapped-by="master">
            <collection element-type="com.acme.Part"/>
        </field>
        <field name="store" persistence-modifier="persistent">
        </field>

<sequence name="messageSeq" datastore-sequence="SS_GB_MSGSEQ"/>
    </class>


java.lang.ClassCastException: org.datanucleus.metadata.ClassMetaData cannot be cast to org.datanucleus.metadata.PackageMetaData
at org.datanucleus.api.jdo.metadata.JDOMetaDataHandler.startElement(JDOMetaDataHandler.java:484)
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.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1343)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2756)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
3 at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808)
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:119)
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 javax.xml.parsers.SAXParser.parse(SAXParser.java:395)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:198)
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataStream(MetaDataParser.java:276)
at org.datanucleus.metadata.xml.MetaDataParser.parseMetaDataURL(MetaDataParser.java:137)
at org.datanucleus.api.jdo.metadata.JDOMetaDataManager.parseFile(JDOMetaDataManager.java:239)
at org.datanucleus.api.jdo.metadata.JDOMetaDataManager.loadXMLMetaDataForClass(JDOMetaDataManager.java:763)
at org.datanucleus.api.jdo.metadata.JDOMetaDataManager.getMetaDataForClassInternal(JDOMetaDataManager.java:378)
at org.datanucleus.metadata.MetaDataManager.getMetaDataForClass(MetaDataManager.java:1427)
at org.datanucleus.enhancer.RuntimeEnhancer.enhance(RuntimeEnhancer.java:183)
at org.datanucleus.enhancer.DataNucleusClassFileTransformer.transform(DataNucleusClassFileTransformer.java:142)
at sun.instrument.TransformerManager.transform(TransformerManager.java:169)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:365)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Sort Order: Ascending order - Click to sort in descending order
Chris Colman added a comment - 27/Mar/13 05:35 AM
I got it to work by removing the <sequence> element. It worked but it gives this warning on startup:

[ValueGeneration] Field com.acme.MyClass (datastore id) has been specified to use sequence SS_GB_MSGSEQ but there is no <sequence> specified in the MetaData. Falling back to use a sequence in the datastore with this name directly.

NOTE: the 'name' attribute in the above was actually 'ms' not 'messageSeq' as it says above.

Andy Jefferson added a comment - 27/Mar/13 09:24 AM
Since when has JDO DTD/XSD accepted <sequence> at <class> level?

Chris Colman added a comment - 27/Mar/13 09:34 AM
The sequence sample metadata on this page:

http://www.datanucleus.org/products/datanucleus/jdo/value_generation.html

is

<class name="myclass" ... >
    <datastore-identity strategy="sequence" sequence="yourseq"/>
    ...
    <sequence name="yourseq" datastore-sequence="YOUR_SEQUENCE_NAME"/>
</class>

Isn't that showing it at class level?

Andy Jefferson added a comment - 27/Mar/13 02:40 PM
So the doc *was* wrong. The XSD and DTD have always been public, and the code has always matched those. Obviously users could contribute docs too.

Chris Colman added a comment - 28/Mar/13 12:05 AM
Just one more tweak ;) ...

The updated sequence metadata sample is not valid because according to the XSD 'strategy' is a required attribute:


    <xs:attributeGroup name="attlist.sequence">
        <xs:attribute name="name" use="required"/>
        <xs:attribute name="datastore-sequence"/>
        <xs:attribute name="factory-class"/>
        <xs:attribute name="strategy" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:token">
                    <xs:enumeration value="nontransactional"/>
                    <xs:enumeration value="contiguous"/>
                    <xs:enumeration value="noncontiguous"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
        <xs:attribute name="initial-value" default="1"/>
        <xs:attribute name="allocation-size" default="50"/>
    </xs:attributeGroup>

Perhaps the sample metadata could be changed to:

<sequence name="yourseq" datastore-sequence="YOUR_SEQUENCE_NAME" ... />
<class name="myclass" ... >
    <datastore-identity strategy="sequence" sequence="yourseq"/>
    ...
</class>

i.e. add '...' to the sequence element to indicate that it's an incomplete example or perhaps we could just add the attribute: strategy="contiguous" to make it a complete, valid example.