0

I´ve just started playing around with Java and Hibernate and have gotten an application working. Everything works "perfectly" when I run it from eclipse but when I use Eclipse builtin function for packaging the project with dependencies into a jar files I get:

org.hibernate.InvalidMappingException: Unable to read XML
        at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)
        at org.hibernate.cfg.Configuration.add(Configuration.java:510)
        at org.hibernate.cfg.Configuration.add(Configuration.java:506)
        at org.hibernate.cfg.Configuration.add(Configuration.java:686)
        at org.hibernate.cfg.Configuration.addResource(Configuration.java:771)
        at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2314)
        at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2280)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2260)
        at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2213)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
        at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
        at myPackage.MyClass.setUp(MyClass.java:89)

The hibernate.cfg.xml and mapping.hbm.xml are both located directly in the src folder. Tthe "link" between them is:

<mapping resource="mapping.hbm.xml" />

In the resulting jar-file they both end up in the root.

1 Answer 1

1

Your message could have several explanations regarding XML validity.

In my case, I had the same problem the whole day but with a legacy application, so it couldn't be invalid. I just realized that there were a crash in my classpath so dfc.jar file was interfering with Hibernate when reading XML mappings.

In your case it could be a question of XML validity (as you can see all around the web), or another JAR file interfering your classpath as in my case.

I hope it helps.

Sign up to request clarification or add additional context in comments.

1 Comment

It was some kind of overwriting of jar-files from different sources. Readded them all - newest version available and the problem went away.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.