title: Hibernate - ServiceRegistryBuilder
body: <p>I'm just trying to learn Hibernate (version 4 final) but I have a problem when trying to create the session factory. Here is some code related to the problem:
  <br/><br/>
  hibernate.cfg.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
      &lt;property name="connection.url"&gt;jdbc:mysql://localhost/fitterblog&lt;/property&gt;
      &lt;property name="connection.username"&gt;root&lt;/property&gt;
      &lt;property name="connection.password"&gt;&lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
  
      &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt;
      &lt;property name="transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/property&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!--&lt;mapping class="com.fitterblog.objects.Article"/&gt;
      &lt;mapping class="com.fitterblog.objects.Nav"/&gt;
      &lt;mapping class="com.fitterblog.objects.Tag"/&gt;
      &lt;mapping class="com.fitterblog.objects.User"/&gt;--&gt;
  
  &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p><br/></p>
  
  <p>HibernateUtil.java:</p>
  
  <pre><code>public class HibernateUtil {
  
      private static final SessionFactory sessionFactory = buildSessionFactory();
  
      private static SessionFactory buildSessionFactory() {
          try {
              // Create the SessionFactory from hibernate.cfg.xml
  
              ServiceRegistryBuilder srb = new ServiceRegistryBuilder();
  
              //NOTE: THIS IS WHERE MY PROGRAM DIES!!
              srb = srb.configure();
  
              ServiceRegistry sr = srb.buildServiceRegistry();
              MetadataSources mds = new MetadataSources(sr);
              /*mds.addAnnotatedClass(com.fitterblog.objects.Article.class);
              mds.addAnnotatedClass(com.fitterblog.objects.Nav.class);
              mds.addAnnotatedClass(com.fitterblog.objects.Tag.class);
              mds.addAnnotatedClass(com.fitterblog.objects.User.class);*/
              return mds.buildMetadata().buildSessionFactory();
          } catch (Throwable ex) {
              System.err.println("Initial SessionFactory creation failed." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  }
  </code></pre>
  
  <p><br/>
  Now, what seems to be the problem is creating the ServiceRegistryBuilder. When the code execution gets to that point, it gives me the following error:</p>
  
  <pre><code>org.hibernate.internal.util.config.ConfigurationException: 
  Unable to perform unmarshalling at line number 14 and 
  column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1:
  Cannot find the declaration of element 'hibernate-configuration'.
  </code></pre>
  
  <p><br/>
  <br/>
  full error log:</p>
  
  <pre><code>run:
  Dec 27, 2011 12:51:12 PM org.hibernate.Version logVersion
  INFO: HHH000412: Hibernate Core {4.0.0.Final}
  Dec 27, 2011 12:51:12 PM org.hibernate.cfg.Environment &lt;clinit&gt;
  INFO: HHH000206: hibernate.properties not found
  Dec 27, 2011 12:51:12 PM org.hibernate.cfg.Environment buildBytecodeProvider
  INFO: HHH000021: Bytecode provider name : javassist
  Initial SessionFactory creation failed. org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 14 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
  Exception in thread "main" java.lang.ExceptionInInitializerError
  at com.fitterblog.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:33)
  at com.fitterblog.hibernate.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:18)
  at com.fitterblog.objects.Article.list(Article.java:31)
  at main.main(main.java:20)
  Caused by: org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 14 and column 26 in RESOURCE hibernate.cfg.xml. Message: cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.
  at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:120)
  at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:69)
  at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:162)
  at org.hibernate.service.ServiceRegistryBuilder.configure(ServiceRegistryBuilder.java:147)
  at com.fitterblog.hibernate.HibernateUtil.buildSessionFactory(HibernateUtil.java:23)
  ... 3 more
  Caused by: javax.xml.bind.UnmarshalException
   - with linked exception:
  [org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 26; cvc-elt.1: Cannot find the declaration of element 'hibernate-configuration'.]
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(UnmarshallerImpl.java:419)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:356)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:326)
  at org.hibernate.service.internal.JaxbProcessor.unmarshal(JaxbProcessor.java:108)
  ... 7 more
  Caused by: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 26; cvc-elt.1:       Cannot find the declaration of element 'hibernate-configuration'.
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
  at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
  at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
  at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1897)
  at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:737)
  at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorHandlerImpl.startElement(ValidatorHandlerImpl.java:564)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.ValidatingUnmarshaller.startElement(ValidatingUnmarshaller.java:86)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.InterningXmlVisitor.startElement(InterningXmlVisitor.java:60)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(StAXStreamConnector.java:232)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:166)
  at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:354)
  ... 9 more
  Java Result: 1
  BUILD SUCCESSFUL (total time: 7 seconds)
  </code></pre>
  
  <p><br/>
  How do I fix this? I can't seem to find a solution myself.</p>