233 words

Is named-query supported in orm.xml

2011-10-12 14:50

I prefer to keep custom JPQL named queries in an external file, e.g. orm.xml, rather than in the entity classes, for example:

  <named-query name= "DataValue.deleteByCapabilityAndCreationtime">
        <query>delete from DataValue d
                    where d.capabilityId = :capabilityId
                    and d.creationtime &lt;= :creationtime

This works fine with e.g. eclipseLink and postgres, but objectDB complains with an error like:

org.xml.sax.SAXParseException; lineNumber: 524; columnNumber: 70; cvc-complex-type.2.4.a: Invalid content was found starting with element 'named-query'. One of '{"http://java.sun.com/xml/ns/persistence/orm":entity, "http://java.sun.com/xml/ns/persistence/orm":embeddable}' is expected.

Does ObjectDB support externalised named queries, if so what's the recommended way to do it?


freddieFishCake's picture
Joined on 2011-08-30
User Post #14
2011-10-12 15:33

It should be supported by ObjectDB. The error message indicates that the XML fails to pass validation against the JPA 2 ORM schema, probably because of the location of the named-query element in the XML file.

Maybe EclipseLink is more flexible and doesn't enforce the formal schema.

Global named queries should be defined in the XML before any type (entity, embeddable, etc.) definition. Named queries can also be defined in the XML of a specific entity after generator definition (if any) and before listener and attribute definitions.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support's picture
Joined on 2010-05-03
User Post #666
2011-10-12 15:49

yes, well spotted, many thanks ;-)


freddieFishCake's picture
Joined on 2011-08-30
User Post #15

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Maximum file size: 32 MB