• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Could not parse hibernate.cfg.xml

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rashid...
Can You post the trace of error your code is throwing?
Thanks
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<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
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 189
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Buddy. I had the same issue and it got resolved now.
 
Shiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic