2

Hi am writing a simple hibernate program using anotation, below is my hibernate.cfg.xml file:

 <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>

    <!-- Database connection settings -->
    <property name="connection.driver_class">oracle.jdbc.OracleDriver</property>
    <property name="connection.url">jdbc:oracle:thin:@127.0.0.1:1521:XE</property>
    <property name="connection.username">vikas</property>
    <property name="connection.password">vikas</property>>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>

    <!-- Disable the second-level cache  -->
    <!-- <property name="cache.provider_class">org.hibernate.cache.internal.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">create</property>

    <!-- Name the annotated Entity -->
    <mapping class="org.vikas.hibernate.dto.UserDetails"></mapping>
</session-factory>

When i am trying to rum my program it throws following exception:

   16:41:07.592 [main] ERROR org.hibernate.util.XMLHelper - Error parsing XML:         
/hibernate.cfg.xml(56) The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
16:41:07.599 [main] ERROR org.hibernate.cfg.Configuration - problem parsing configuration/hibernate.cfg.xml
Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1222)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1161)
    at org.hibernate.cfg.Configuration.configure(Configuration.java:1147)
    at org.vikas.hibernate.dto.MainTest.main(MainTest.java:18)
Caused by: org.hibernate.MappingException: invalid configuration
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1218)
    ... 3 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 56; columnNumber: 23; The content of element type "session-factory" must match "(property*,mapping*,(class-cache|collection-cache)*,event*,listener*)".
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.dom4j.io.SAXReader.read(SAXReader.java:465)
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1217)
    ... 3 more

Could you please tell me, where i am going wrong.

2
  • The message complains about the line 56, and the file you posted doesn't have so many lines, so either you didn't post the whole file, or this file is not the file that Hibernate parses. Commented Jan 13, 2013 at 14:55
  • I have removed some comments from config file, line number 56 is: </session-factory> Commented Jan 13, 2013 at 17:22

1 Answer 1

1

The problem is one wrong character or missing character in your file.

For example in the line

   <property name="connection.password">vikas</property>>

you have an extra '>' at the end. I don't know if this is the error or if it happened when you removed the comments. If this is not the error then have a look for other wrong characters. This even might be an invisible character (but not a simple space, they are harmless). One time it happened to me the error was a missing line feed after the </hibernate-configuration> tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.