Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate not connecting to database
    text
    copied!<p>So I'm trying to connect to my postgresql database on localhost threw hibernate but I always get errors when I try to connect and really don't know what the problem is.</p> <pre><code>&gt; SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found Exception in thread "main" java.lang.ExceptionInInitializerError at persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:18) at persistence.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:8) at com.hp.videotheek.App.main(App.java:15) Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170) at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2176) at org.hibernate.cfg.Configuration.configure(Configuration.java:2157) at org.hibernate.cfg.Configuration.configure(Configuration.java:2137) at persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:13) ... 2 more </code></pre> <p>This is what I get from the log in eclipse</p> <pre><code> import org.hibernate.Session; import persistence.HibernateUtil; public class App { public static void main( String[] args ) { Session session=HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); } } </code></pre> <p>this is where i want to make the conenction</p> <pre><code> package persistence; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { private static final SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { try { return new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static SessionFactory getSessionFactory() { return sessionFactory; } public static void shutdown() { getSessionFactory().close(); } } </code></pre> <p><img src="https://i.stack.imgur.com/pym3Z.png" alt="enter image description here"></p> <p>this is my file setup</p> <p><strong>NEW ERROR</strong></p> <pre><code> SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Initial SessionFactory creation failed.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml Exception in thread "main" java.lang.ExceptionInInitializerError at persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:16) at persistence.HibernateUtil.&lt;clinit&gt;(HibernateUtil.java:8) at com.hp.videotheek.App.main(App.java:11) Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2246) at org.hibernate.cfg.Configuration.configure(Configuration.java:2158) at org.hibernate.cfg.Configuration.configure(Configuration.java:2137) at persistence.HibernateUtil.buildSessionFactory(HibernateUtil.java:12) ... 2 more Caused by: org.dom4j.DocumentException: Error on line 1 of document : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. at org.dom4j.io.SAXReader.read(SAXReader.java:482) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2238) ... 5 more &lt;!--&lt;span class="hiddenSpellError" pre=""--&gt;DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" &lt;a href="http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&lt;/a&gt;&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;!-- Database connection settings --&gt; jdbc:postgresql://localhost:5432/postgres &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt; &lt;property name="connection.username"&gt;postgres&lt;/property&gt; &lt;property name="connection.password"&gt;****&lt;/property&gt; &lt;property name="transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/property&gt; &lt;!-- SQL dialect - generate SQL for a particular database --&gt; &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt; &lt;!-- Echo all executed SQL statements --&gt; &lt;property name="show_sql"&gt;true&lt;/property&gt; &lt;!-- Enable Hibernate's automatic session context management --&gt; &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt; &lt;!-- Mapping resource configuration files --&gt; &lt;mapping resource="src/com/bookstore/bookapp.hbm.xml"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload