2

When I'm trying to lunch my project I get the Java PersistenceException here the part where I'm creating EntitiyManagerFactory:

package com.politechnika.hibernatealone.application;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.dom4j.tree.BackedList;

import javassist.expr.NewArray;

public class DataToCreateBase {

    static EntityManagerFactory factory = Persistence.createEntityManagerFactory("hibernateAlone");
    public static EntityManager manager = factory.createEntityManager();

And here's the error I get:

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at com.politechnika.hibernatealone.application.DataToCreateBase.<clinit>(DataToCreateBase.java:24)
Caused by: org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)

I've checked the port, password and username - they're correct.

I'm adding also the persistance.xml and pic of database schema https://imgur.com/3c866e26-eb39-4d44-9db3-c262c48fe749

I there something I should add to persistance file?

Persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">

    <persistence-unit name="hibernateAlone">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.politechnika.hibernatealone.domain.Uzytkownik</class>

        <class>com.politechnika.hibernatealone.domain.Dzial</class>
        <class>com.politechnika.hibernatealone.domain.Wydawnictwo</class>
        <class>com.politechnika.hibernatealone.domain.Wojewodztwo</class>

        <!-- the JNDI data source -->
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
            <property name="hibernate.connection.username" value="postgres"/>
            <property name="hibernate.connection.password" value="admin"/>
            <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5433/postgres"/>

            <property name="hibernate.default_schema" value="dbtest"/>

            <property name="hibernate.hbm2ddl.auto" value="create"/>

            <property name="show_sql" value="true"/>
        </properties>
    </persistence-unit>
</persistence>
PiiiTeeeR
  • 45
  • 3

0 Answers0