无法创建请求的服务[org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] Hibernate Java

时间:2018-12-08 15:12:11

标签: java hibernate

我无法编译我的程序,无法从远程数据库中获取数据,下面我添加了persistance.xml,当我想要编译我的程序时,我无法创建请求的服务[org.hibernate.engine.jdbc.env .spi.JdbcEnvironment]错误。 我该怎么办?

Persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                            http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="hibernate-dynamic" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider    </provider>
        <properties>
            <!-- Configuring JDBC properties -->
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://mysql.wmi.amu.edu.pl:3306/s434739_pracownia?useSSL=false"/>
            <property name="javax.persistence.jdbc.user" value="s434739"/>
            <property name="javax.persistence.jdbc.password" value="pracownia0"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />

            <!-- Hibernate properties -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.hbm2ddl.auto" value="validate"/>
            <property name="hibernate.format_sql" value="false"/>
            <property name="hibernate.show_sql" value="true"/>

        </properties>
</persistence-unit>

App.class

public class App {
private static EntityManager entityManager = null;
private static EntityManagerFactory entityManagerFactory = null;
public static void main( String[] args ) {

    try {
        entityManagerFactory = 
        Persistence.createEntityManagerFactory("hibernate");
        entityManager = entityManagerFactory.createEntityManager();
    } catch (Exception ex) {
        System.out.println("ERR: " + ex.getMessage());
    }

    MainLogic mainLogic = new MainLogic();
    mainLogic.getThemAll(entityManager);
    mainLogic.printThemAll();
}

}

MainLogic.class

void getThemAll(EntityManager entityManager)  {

    for(String tableName: tableNames) {
        String str = "SELECT k FROM " + tableName + " k";
        Query query = entityManager.createQuery("SELECT k FROM BrandAmbassador k");
        if(tableName.equals("Ambasadorzy_marki"))
            brandAmbassadorList = query.getResultList();
        if(tableName.equals("Kategorie"))
            categoryList = query.getResultList();
        if(tableName.equals("Producenci"))
            brandList = query.getResultList();
        if(tableName.equals("Produkty"))
            productList = query.getResultList();
        if(tableName.equals("Samochody_sluzbowe"))
            companyCarList = query.getResultList();
    }

   // this.entityManager.close();
}

0 个答案:

没有答案