Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Liutauras Vilda
Ron McLeod
Sheriffs:
Jeanne Boyarsky
Devaka Cooray
Paul Clapham
Saloon Keepers:
Scott Selikoff
Tim Holloway
Piet Souris
Mikalai Zaikin
Frits Walraven
Bartenders:
Stephan van Hulst
Carey Brown
Forum:
Object Relational Mapping
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document
Robert Jack
Ranch Hand
Posts: 53
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
i got error while i run my simple application. The application details:
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hbm2ddl.auto">create</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:TEST</property> <property name="connection.username">root</property> <property name="connection.password">test123</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <mapping resource="entities.hbm.xml" /> </session-factory> </hibernate-configuration>
entities.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.hibernate.entities.Person" table="Person"/> </hibernate-mapping>
Person.java
package com.hibernate.entities; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "Person") public class Person { public Person() { } @Id @Column(name = "id") Integer id; @Column(name = "name", length = 16, nullable = true) String name; @Column(name = "surname", length = 16, nullable = true) String surname; @Column(name = "address", length = 16, nullable = true) String address; public Integer getId(){ return id; } public void setId(Integer id){ this.id = id; } public String getName(){ return name; } public void setName(String name){ this.name = name; } public String getSurname(){ return surname; } public void setSurname(String surname){ this.surname = surname; } public String getAddress(){ return address; } public void setAddress(String address) { this.address = address; } }
PersonDAL.java
package com.hibernate.user.dal; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import com.hibernate.entities.Person; public class PersonDAL { public static void main(String args[]) { PersonDAL personDAL = new PersonDAL(); personDAL.addPersonDetails(); } public void addPersonDetails() { Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xml"); if (cfg != null) { SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Transaction t = session.beginTransaction(); System.out.println("Configuration finished!!!"); Person person = new Person(); person.setId(1); person.setName("Michel"); person.setSurname("Jackson"); person.setAddress("USA"); session.merge(person);// persisting the object System.out.println("The details are saved successfully"); t.commit(); session.close(); } else { System.out.println("Configuration object is null while store the details"); } } }
Error
Start... log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource entities.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:569) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1587) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508) at org.hibernate.cfg.Configuration.configure(Configuration.java:1428) at com.hibernte.startup.ConfigLoader.loadConfig(ConfigLoader.java:13) at com.hibernate.user.dal.PersonDAL.<init>(PersonDAL.java:14) at com.hibernate.user.ui.PersonUI.main(PersonUI.java:14) Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from invalid mapping at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:502) at org.hibernate.cfg.Configuration.addResource(Configuration.java:566) ... 8 more Caused by: org.xml.sax.SAXParseException; lineNumber: 5; columnNumber: 65; The content of element type "class" is incomplete, it must match "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,resultset*,(query|sql-query)*)". at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:499) ... 9 more
Please help me this.
Thanks in advance.
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mappin
Invalid mapping exception in Hibernate
Problem with Hibernate test application
Hibernate exception for one-to-one mapping
org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
More...