I am using Hibernate 3.5.1 with maven to create a JPA application utilizing JPA 2.0 and Spring. I am not using Spring's JpaDaoSupport or those classes, I am just configuring an EntityManager that gets injected into my class.
When I try to define an element-collection element, which appears to be supported by JPA documentation as well as the schema for the orm file, it produces a parsing error (not sure if Hibernate is validating the file while parsing it)?
The parsing error says that element-collection is not allowed and if I check the schema, it is allowed and in the correct position.
Any thoughts?
Thanks,
Jay
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="1.0">
<description>com.foo.Provider Entity Mapping</description>
<persistence-unit-metadata>
<xml-mapping-metadata-complete/>
</persistence-unit-metadata>
<package>com.foo</package>
<!--schema>PROVIDER</schema-->
<entity class="Provider" metadata-complete="true" access="FIELD">
<table name="PROVIDER"/>
<attributes>
<basic name="providerType">
<column name="PROVIDERTYPE"/>
</basic>
<basic name="providerStatus">
<column name="PROVIDERSTATUS"/>
</basic>
<basic name="contractStatus">
<column name="CONTRACTSTATUS"/>
</basic>
<basic name="region">
<column name="REGION"/>
</basic>
<one-to-many name="specialities" fetch="LAZY" target-entity="com.foo.Specialty"/>
<one-to-many name="languages" fetch="LAZY" target-entity="com.foo.Language"/>
<one-to-many name="locations" fetch="LAZY" target-entity="com.foo.Location"/>
<one-to-many name="rates" fetch="LAZY" target-entity="com.foo.Rate"/>
<one-to-many name="institutionalAdmission" fetch="LAZY" target-entity="com.foo.InstitutionalAdmission"/>
<element-collection name="facilities" fetch="LAZY">
<collection-table name="facilitiesTable">
<join-column name="facilities"/>
</collection-table>
</element-collection>
</attributes>
</entity>
</entity-mappings>
Caused by: org.hibernate.MappingException: invalid mapping: com/foo/Provider-orm.xml
at org.hibernate.ejb.Ejb3Configuration.addXMLEntities(Ejb3Configuration.java:714)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:589)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:72)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
... 54 more
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'element-collection'. One of '{"http://java.sun.com/xml/ns/persistence/orm":one-to-many, "http://java.sun.com/xml/ns/persistence/orm":one-to-one, "http://java.sun.com/xml/ns/persistence/orm":many-to-many, "http://java.sun.com/xml/ns/persistence/orm":embedded, "http://java.sun.com/xml/ns/persistence/orm":transient}' is expected.
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:417)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.reportSchemaError(XMLSchemaValidator.java:3181)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1805)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2755)
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: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 org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.dom4j.io.SAXReader.read(SAXReader.java:343)
at org.hibernate.ejb.Ejb3Configuration.addXMLEntities(Ejb3Configuration.java:712)
... 60 more