java - Hibernate 4. Invalid Mapping Exception. Unable to read XML. Element type hibernate-mapping must be declared -


i have invalidmappingexception on org.hibernate.cfg.configuration.configure() method call.

stack trace:

 javax.servlet.servletexception: org.hibernate.invalidmappingexception: unable read xml     org.apache.struts.chain.composablerequestprocessor.process(composablerequestprocessor.java:286)     org.apache.struts.action.actionservlet.process(actionservlet.java:1913)     org.apache.struts.action.actionservlet.dopost(actionservlet.java:462)     javax.servlet.http.httpservlet.service(httpservlet.java:647)     javax.servlet.http.httpservlet.service(httpservlet.java:728)  root cause  org.hibernate.invalidmappingexception: unable read xml     org.hibernate.internal.util.xml.mappingreader.readmappingdocument(mappingreader.java:109)     org.hibernate.cfg.configuration.add(configuration.java:488)     org.hibernate.cfg.configuration.add(configuration.java:484)     org.hibernate.cfg.configuration.add(configuration.java:657)     org.hibernate.cfg.configuration.addresource(configuration.java:740)     org.hibernate.cfg.configuration.parsemappingelement(configuration.java:2188)     org.hibernate.cfg.configuration.parsesessionfactory(configuration.java:2160)     org.hibernate.cfg.configuration.doconfigure(configuration.java:2140)     org.hibernate.cfg.configuration.doconfigure(configuration.java:2093)     org.hibernate.cfg.configuration.configure(configuration.java:2008)     org.hibernate.cfg.configuration.configure(configuration.java:1987)     com.petrez.util.hibernateutil.getsessionfactory(hibernateutil.java:12)     com.action.useraction.setuser(useraction.java:29)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:601)     org.apache.struts.actions.dispatchaction.dispatchmethod(dispatchaction.java:269)     org.apache.struts.actions.dispatchaction.execute(dispatchaction.java:170)     org.apache.struts.chain.commands.servlet.executeaction.execute(executeaction.java:58)     org.apache.struts.chain.commands.abstractexecuteaction.execute(abstractexecuteaction.java:67)     org.apache.struts.chain.commands.actioncommandbase.execute(actioncommandbase.java:51)     org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     org.apache.commons.chain.generic.lookupcommand.execute(lookupcommand.java:305)     org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     org.apache.struts.chain.composablerequestprocessor.process(composablerequestprocessor.java:283)     org.apache.struts.action.actionservlet.process(actionservlet.java:1913)     org.apache.struts.action.actionservlet.dopost(actionservlet.java:462)     javax.servlet.http.httpservlet.service(httpservlet.java:647)     javax.servlet.http.httpservlet.service(httpservlet.java:728)  root cause  org.xml.sax.saxparseexception; systemid: ; linenumber: 5; columnnumber: 47; element type "hibernate-mapping" must declared.     org.apache.xerces.framework.xmlparser.reporterror(xmlparser.java:1213)     org.apache.xerces.validators.common.xmlvalidator.reportrecoverablexmlerror(xmlvalidator.java:1807)     org.apache.xerces.validators.common.xmlvalidator.validateelementandattributes(xmlvalidator.java:3633)     org.apache.xerces.validators.common.xmlvalidator.callstartelement(xmlvalidator.java:1229)     org.apache.xerces.framework.xmldocumentscanner.scanelement(xmldocumentscanner.java:1806)     org.apache.xerces.framework.xmldocumentscanner$contentdispatcher.dispatch(xmldocumentscanner.java:949)     org.apache.xerces.framework.xmldocumentscanner.parsesome(xmldocumentscanner.java:381)     org.apache.xerces.framework.xmlparser.parse(xmlparser.java:1098)     org.dom4j.io.saxreader.read(saxreader.java:465)     org.hibernate.internal.util.xml.mappingreader.readmappingdocument(mappingreader.java:78)     org.hibernate.cfg.configuration.add(configuration.java:488)     org.hibernate.cfg.configuration.add(configuration.java:484)     org.hibernate.cfg.configuration.add(configuration.java:657)     org.hibernate.cfg.configuration.addresource(configuration.java:740)     org.hibernate.cfg.configuration.parsemappingelement(configuration.java:2188)     org.hibernate.cfg.configuration.parsesessionfactory(configuration.java:2160)     org.hibernate.cfg.configuration.doconfigure(configuration.java:2140)     org.hibernate.cfg.configuration.doconfigure(configuration.java:2093)     org.hibernate.cfg.configuration.configure(configuration.java:2008)     org.hibernate.cfg.configuration.configure(configuration.java:1987)     com.petrez.util.hibernateutil.getsessionfactory(hibernateutil.java:12)     com.action.useraction.setuser(useraction.java:29)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57)     sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     java.lang.reflect.method.invoke(method.java:601)     org.apache.struts.actions.dispatchaction.dispatchmethod(dispatchaction.java:269)     org.apache.struts.actions.dispatchaction.execute(dispatchaction.java:170)     org.apache.struts.chain.commands.servlet.executeaction.execute(executeaction.java:58)     org.apache.struts.chain.commands.abstractexecuteaction.execute(abstractexecuteaction.java:67)     org.apache.struts.chain.commands.actioncommandbase.execute(actioncommandbase.java:51)     org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     org.apache.commons.chain.generic.lookupcommand.execute(lookupcommand.java:305)     org.apache.commons.chain.impl.chainbase.execute(chainbase.java:191)     org.apache.struts.chain.composablerequestprocessor.process(composablerequestprocessor.java:283)     org.apache.struts.action.actionservlet.process(actionservlet.java:1913)     org.apache.struts.action.actionservlet.dopost(actionservlet.java:462)     javax.servlet.http.httpservlet.service(httpservlet.java:647)     javax.servlet.http.httpservlet.service(httpservlet.java:728)  

config file: hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-configuration public "-//hibernate/hibernate configuration dtd 3.0//en" "http://www.hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration>     <session-factory>         <property name="hibernate.bytecode.use_reflection_optimizer">false</property>         <property name="hibernate.connection.driver_class">com.mysql.jdbc.driver</property>         <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/library</property>         <property name="hibernate.connection.username">root</property>         <property name="hibernate.connection.password">g190419g</property>         <property name="hibernate.dialect">org.hibernate.dialect.mysqldialect</property>         <property name="hibernate.show_sql">false</property>         <property name="hibernate.current_session_context_class">thread</property>         <property name="hibernate.cglib.use_reflection_optimizer">false</property>         <property name="hibernate.c3p0.acquire_increment">1</property>         <property name="hibernate.c3p0.idle_test_period">3000</property>         <property name="hibernate.c3p0.max_size">100</property>         <property name="hibernate.c3p0.max_statements">50</property>         <property name="hibernate.c3p0.min_size">10</property>         <property name="hibernate.c3p0.timeout">100</property>         <property name="hibernate.c3p0.testconnectiononcheckout">true</property>         <mapping resource="com/petrez/model/users.hbm.xml" />     </session-factory> </hibernate-configuration> 

mapping file: users.hbm.xml

<?xml version='1.0' encoding='utf-8'?> <!doctype hibernate-mapping public         "-//hibernate/hibernate mapping dtd 3.0//en"         "http://www.hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.petrez.model">     <class name="users" table="users" >         <id name="id" column="id" type="java.lang.integer" >             <generator class="increment"/>         </id>          <property name="firstname" type="java.lang.string">             <column name="firstname" length="45" />         </property>          <property name="lastname" type="java.lang.string">             <column name="lastname" length="45" />         </property>          <property name="email" type="java.lang.string">             <column name="email" length="45" />         </property>     </class> </hibernate-mapping> 

so can me here mistake? thanks.

upd: project structure.

project structure

well. didn't find solution, annotations helped me.

change type of mappings java types hibernate types: string giving example:

 <property name="logmsg" type="string">             <column name="log_msg" length="35" />         </property>  

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -