当我试图在我的项目中吃午饭时,我得到了Java PersistenceException 这里是我创建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();
这是我得到的错误:
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)
我已经检查了端口,密码和用户名 - 他们正确无误。
我还添加了数据库架构https://imgur.com/3c866e26-eb39-4d44-9db3-c262c48fe749
的persistance.xml和pic我有什么东西需要添加到persistance文件中?
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>