title: Hibernate going crazy after trying to have 2 hibernate.cfg.xml for 2 DB
body: <p><strong>EDIT: Before reading the question:</strong> <strong>deleting the folder in wildfly deployment "solved" the issue. But I didn't put back my code for the other DB. Is the way I did it was right?</strong></p>
  
  <p>I was working this morning, everything was going fine.</p>
  
  <p>I added a dependency which is the core of another maven project and the goal was to use that project to add data in the database of that project, not the one of my current project.</p>
  
  <p>So I tried a lot of stuff, but at the end it was working. And then, I left to go eat. </p>
  
  <p>The server is host on my computer, so localhost and I left it like that for about an hour.</p>
  
  <p>Here's what I did:</p>
  
  <ol>
  <li><p>Create new <code>hibernate.cfg.xml</code> in <code>src/main/resources</code> with properties.</p>
  
  <p>So I had 2 <code>hibernate.cfg.xml</code> in my project. The original one in <code>src/main/resources/my/hibernate/package/</code> and the new one in the <code>default</code> package.</p></li>
  <li><p>In my code -> </p>
  
  <pre><code>Configuration cfg = new Configuration();
  cfg.configure();
  </code></pre></li>
  </ol>
  
  <p>Note that before doing only that, I was setting the properties programmatically and it was working fine.</p>
  
  <p>I thought it was taking the one in default package. <strong>That was working earlier</strong>.</p>
  
  <p>So I came back, try to run the application and get this exception:</p>
  
  <pre><code>Nested exception: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
  </code></pre>
  
  <p>I haven't touch a thing... so I removed all my work (the new <code>hibernate.cfg.xml</code> too), restarted the server, even the computer.</p>
  
  <p>I read about the exception, it says that maybe I have two dom4j, or that I need to put <code>&lt;scope&gt;provided&lt;/scope&gt;</code> to some dependencies.</p>
  
  <p>I added the scope everywhere, removed the dependency of the other project, but it won't help.</p>
  
  <p>I have these logs in my <strong>wildfly</strong> server.log</p>
  
  <pre><code>WFLYCTL0186:   Services which failed to start:      
  
  service jboss.undertow.deployment.default-server.default-host./PROJECT_NAME: 
  org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./PROJECT_NAME: 
  org.springframework.beans.factory.UnsatisfiedDependencyException: 
  Error creating bean with name 'firstControllerInMyDispatcher': 
  Unsatisfied dependency expressed through field 'DAO_name': 
  Error creating bean with name 'DAO_name' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: 
  Cannot resolve reference to bean 'mySessionFactory' while setting constructor argument; 
  
  nested exception is org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: 
  Invocation of init method failed; 
  
  nested exception is org.hibernate.InvalidMappingException: 
  Unable to read XML; 
  
  nested exception is org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'DAO_name' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: 
  Cannot resolve reference to bean 'mySessionFactory' while setting constructor argument; 
  
  nested exception is org.springframework.beans.factory.BeanCreationException: 
  Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: 
  Invocation of init method failed; 
  
  nested exception is org.hibernate.InvalidMappingException: 
  Unable to read XML
  </code></pre>
  
  <p>The dom4j exception only shows in the Netbeans console log and it's after all those same lines:</p>
  
  <pre><code>"{\"WFLYCTL0080: Failed services\" =&gt; {\"[previous exceptions lines]
  Caused by: 
  org.dom4j.DocumentException: 
  org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory Nested exception: 
  org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory\"}}"
  </code></pre>
  
  <p>I'm clueless, can anyone help with this? Thanks.</p>