aspose file tools*
The moose likes Object Relational Mapping and the fly likes Could not parse hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not parse hibernate.cfg.xml" Watch "Could not parse hibernate.cfg.xml" New topic
Author

Could not parse hibernate.cfg.xml

Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
Hello All,
i have a very basic yet strange issue which i am not able to resolve i get this error which is pretty known
Could not parse configuration: /hibernate.cfg.xml
This is my hibernate.cfg.xml file
<?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="hibernate.connection.username">uid</property>
<property name="hibernate.connection.password">uid</property>
<property name="hibernate.connection.url">
jdbc url
</property>
<property name="hibernate.connection.driver_class">
driver class
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>

i get the error when i come across this statement indicated by bold
Configuration config = new Configuration();
config.configure("/hibernate.cfg.xml");
sessionFactory = config.buildSessionFactory();

any help
Rashid
Halcon Guatemala
Ranch Hand

Joined: Sep 06, 2006
Posts: 57
Hi Rashid...
Can You post the trace of error your code is throwing?
Thanks


"La verdadera sabidur´┐Ża viene del temor de Dios"
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
here it is
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1376)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at com.Helper.HibernateUtil.<clinit>(HibernateUtil.java:26)
at com.action.TestAction.execute(TestAction.java:35)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at com.action.MainActionController.process(MainActionController.java:22)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:996)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6452)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3661)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2630)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)
Caused by: org.dom4j.DocumentException: Error on line 21 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1366)
... 20 more
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

<property name="hibernate.connection.username">uid</property>
<property name="hibernate.connection.password">uid</property>
<property name="hibernate.connection.url">
jdbc url
</property>


You did not set up your connection to the database, so when the Configuration object/Session Factory tries to be created it fails because it can't connect to the database and create a connection pool.

You need to fill in the correct values for those properties.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
i didn't put jdbc url for security purpose

let me put hte file one more time here

<?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="hibernate.connection.username">evdb</property>
<property name="hibernate.connection.password">evdb</property>
<property name="hibernate.connection.url">
jdbc racle:thin:@xxx.xx.x.xx:6565:tyes
</property>
<property name="hibernate.connection.driver_class">
oracle.jdbc.OracleDriver
</property>
<property name="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<mapping resource="Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Can you repost it again, but this time, there is a "CODE" button below that if you put your file between the CODE tags that it creates, the indentation and formatting will remain. I am trying to see if you have forgotten to close a tag, or nested tags that shouldn't be nested, but unformatted makes it too tough to read, and this time you can "for security purposes" not put in that stuff.

Thanks

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Caused by: org.dom4j.DocumentException: Error on line 21 of document : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.


I remember seeing such an exception, in one of my sample applications(though it had nothing to do with Hibernate). The reason behind this exception(if i remember correctly) was that my xml file did not have:



on its first line. Check whether its the same case in your hibernate.cfg.xml. That tag should appear on the first line of the xml.


[My Blog] [JavaRanch Journal]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Originally posted by Jaikiran Pai:


I remember seeing such an exception, in one of my sample applications(though it had nothing to do with Hibernate). The reason behind this exception(if i remember correctly) was that my xml file did not have:



on its first line. Check whether its the same case in your hibernate.cfg.xml. That tag should appear on the first line of the xml.



Scrolling up to an earlier of his posts, it looks like that is exactly what he has as the first line.

Just out of curiosity, make sure there is no space or carriage return before that first line.

Mark
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
Phew!!!
Thanks a lot guys that was the issue.
in my faintest idea i never thought that was the issue, but nice catch.

it works now
Rashid
Govindharaj Varadharajan
Greenhorn

Joined: Jan 18, 2010
Posts: 2
Thanks Buddy. I had the same issue and it got resolved now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not parse hibernate.cfg.xml