Reputation: 763
I am trying to develop a dynamic web project in Eclipse. I am using hibernate 3, tomcat 6 . My web page has a simple registration form. It accepts the user data and adds it to the db. I am using hibernate to do that part. I am getting this error. Have tried the solutions given in some of the similar questions asked but could not solve the issue. The error that I get is
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
May 23, 2014 10:20:30 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet NavigationController threw exception
org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
at com.pkg.dao.UserDAO.registeruser(UserDAO.java:58)
at com.pkg.controller.NavigationController.doPost(NavigationController.java:60)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: org.dom4j.DocumentException: hibernate.sourceforge.net Nested exception: hibernate.sourceforge.net
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
... 17 more
My Customer.hbm.xml file is
<?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>
<class name="com.pkg.bean.CustomerBean" table="r_customer">
<id name="CUSTOMERID" column="CUSTOMERID" type="String">
<generator class="assigned"/>
</id>
<property name="PASSWORD" column="PASSWORD" type="String"/>
<property name="CUSTOMERNAME" column="CUSTOMERNAME" type="String"/>
<property name="CONTACTNUMBER" column="CONTACTNUMBER" type="String"/>
</class>
</hibernate-mapping>
And by hibernate config file is
<?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>
<!-- Database connection settings -->
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:javadb</property>
<property name="connection.username">user</property>
<property name="connection.password">password</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto"></property>
<mapping resource="Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Can anyone please help me out solve the issue.
Upvotes: 1
Views: 281
Reputation: 763
The changes that I made to my code to make it work are
In my Customer.hbm.xml
file
I changed the type of column from type="String"
to type="string"
In the hibernate.cfg.xml
file I had create the table in database already so
I commented <property name="hbm2ddl.auto">create</property>
The problem seems to be system specific because the code was working without any hiccups in my home computer but was showing
org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml
error in my office computer.
At home I am using Eclipse Kepler, Tomcat 7 and hibernate 3.6.4 Final
In office there is Eclipse Galileo , Tomcat 6 and hibernate 3.x.x
I am not really sure want really solved the problem or the problem crept-in in the first place.
Upvotes: 1
Reputation: 23637
I noticed that your hibernate.cfg.xml
refers to Customer.hbm.xml
, and that file refers to a class com.pkg.bean.CustomerBean
. It might not be wrong, but it doesn't follow the conventions, so I suspect there might be a problem there:
According to these conventions, hbm.xml
files would be stored in the same package as their class. If that's the case, probably you should be referencing it as com/pkg/bean/Customer.hbm.xml
.
Another convention is to name your files with the same name as your hbm.xml
files. So then it would be CustomerBean.hbm.xml
.
This is just a guess, based on the information you posted. I am not sure if any of these "conventions" are rules that would cause exceptions if broken (it's been a long time since I read the docs, and I usually follow best practices so I never tested to see what would happen if I didn't).
Upvotes: 0
Reputation: 3820
You have empty
<property name="hbm2ddl.auto"></property>
Put some value there update/create
.
Upvotes: 1