GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes MappingException: Could not read mappings from resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "MappingException: Could not read mappings from resource" Watch "MappingException: Could not read mappings from resource" New topic
Author

MappingException: Could not read mappings from resource

Abhinav Sahai
Greenhorn

Joined: May 21, 2008
Posts: 12
Hi,

When I am trying to add filter in my hbm file, I am getting this stack trace, otherwise it is working fine.

Stack Trace:

at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at hibernate.HibernateSessionFactory.getSession(HibernateSessionFactory.java:19)
at database.BatchDAO.getBatchesReady(BatchDAO.java:22)
at businessObjects.MyController.main(MyController.java:30)
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:425)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 8 more
Caused by: org.xml.sax.SAXParseException: The content of element type "hibernate-mapping" must match "(meta*,typedef*,import*,(class|subclass|joined-subclass|union-subclass)*,resultset*,(query|sql-query)*,filter-def*,database-object*)".
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:465)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:422)
... 9 more



FILTER DEF:
<filter-def name="titleFilter">
<filter-param name="titleParam" type="string" />
</filter-def>

I'd be greatful if anyone could help me out.

Thanks.
[ May 21, 2008: Message edited by: Abhinav Sahai ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10141
    
165

Caused by: org.xml.sax.SAXParseException: The content of element type "hibernate-mapping" must match "(meta*,typedef*,import*,(class|subclass|joined-subclass|union-subclass)*,resultset*,(query|sql-query)*,filter-def*,database-object*)"


Abhinav,
Welcome to JavaRanch

Please post the entire hbm file.


[My Blog] [JavaRanch Journal]
Abhinav Sahai
Greenhorn

Joined: May 21, 2008
Posts: 12
Hi Jaikiran,

Thanks for the reply... here is my HBM file..

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<filter-def name="titleFilter">
<filter-param name="titleParam" type="string" />
</filter-def>
<class name="orm.Batch" table="BATCH">

<id name="BatchID" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">PB_ID_SEQ</param>
</generator>
</id>

<property name="batchName" column="BATCH_NAME" type="string"/>
<property name="batchStatusID" column="BATCH_STATUS_ID" type="int"/>
<set name="overlay" table="OVERLAY">
<key column="BATCH_ID"></key>
<one-to-many class="orm.Overlay" />
<filter name="titleFilter" condition=":titleParam = OVERLAY_TYPE" />
</set>
</class>

</hibernate-mapping>
[ May 22, 2008: Message edited by: Abhinav Sahai ]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10141
    
165

The dtd expects the filter-def element to be after the class element. Change your hbm.xml as follows:

Abhinav Sahai
Greenhorn

Joined: May 21, 2008
Posts: 12
Thanks a lot Jaikiran. It worked...
 
GeeCON Prague 2014
 
subject: MappingException: Could not read mappings from resource