2017-10-21 166 views
0

我想設置一個Maven項目來處理Wildfly和MySql,我收到了這個錯誤,我很確定這是一個配置問題。我使用Wildfly,所以我沒有任何hibernate配置文件(這與我找到的所有解決方案有關)。這是我得到的。我剛開始學習如何處理RIA,所以任何想法都將非常感激。Java EE + Wildfly:啓動服務失敗jboss.persistenceunit

問題主要是錯誤日誌和代碼,所以感謝任何願意幫助的人的耐心。

我的控制檯錯誤:

17:53:34,909 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 62) MSC000001: Failed to start service jboss.persistenceunit."RPGo.war#RPGo": org.jboss.msc.service.StartException in service jboss.persistenceunit."RPGo.war#RPGo": org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:195) 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:125) 
    at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:640) 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:209) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
    at org.jboss.threads.JBossThread.run(JBossThread.java:320) 
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:264) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) 
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) 
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:848) 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:875) 
    at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) 
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167) 
    ... 7 more 
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100) 
    at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254) 
    ... 19 more 

17:53:34,909 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "RPGo.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"RPGo.war#RPGo\"" => "org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
    Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set"}} 
17:53:34,940 INFO [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "RPGo.war" (runtime-name : "RPGo.war") 
17:53:34,940 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report 
WFLYCTL0186: Services which failed to start:  service jboss.persistenceunit."RPGo.war#RPGo": org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 

我persistance.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="RPGo"> 
      <provider>org.hibernate.ejb.HibernatePersistence</provider> 
      <jta-data-source>java:jboss/datasources/RPGo</jta-data-source> 
      <exclude-unlisted-classes>false</exclude-unlisted-classes> 
      <properties> 
       <property name="hibernate.hbm2ddl.auto" value="update" /> 
      </properties> 
     </persistence-unit> 
    </persistence> 

standalone.xml,甕:JBoss的:域:數據源子系統

<subsystem xmlns="urn:jboss:domain:datasources:5.0"> 
    <datasources> 
     <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"> 
      <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url> 
      <driver>h2</driver> 
      <security> 
       <user-name>sa</user-name> 
       <password>sa</password> 
      </security> 
     </datasource> 
     <datasource jta="true" jndi-name="java:jboss/datasources/RPGo" pool-name="RPGoPool" enabled="true" use-java-context="true"> 
      <connection-url>jdbc:mysql://localhost:3306/rpgo</connection-url> 
      <driver>mysql</driver> 
      <security> 
       <user-name>master</user-name> 
       <password>master</password> 
      </security> 
     </datasource> 
     <drivers> 
      <driver name="h2" module="com.h2database.h2"> 
       <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class> 
      </driver> 
      <driver name="mysql" module="com.mysql"> 
       <driver-class>com.mysql.jdbc.Driver</driver-class> 
      </driver> 
     </drivers> 
    </datasources> 
</subsystem> 

pom.xml的依賴關係:

<!-- JSF --> 
<dependency> 
    <groupId>com.sun.faces</groupId> 
    <artifactId>jsf-api</artifactId> 
    <version>2.2.13</version> 
</dependency> 

<!-- JSF --> 
<dependency> 
    <groupId>com.sun.faces</groupId> 
    <artifactId>jsf-impl</artifactId> 
    <version>2.2.13</version> 
</dependency> 

<!-- PrimeFaces --> 
<dependency> 
    <groupId>org.primefaces</groupId> 
    <artifactId>primefaces</artifactId> 
    <version>5.3</version> 
</dependency> 

<!-- CDI --> 
<dependency> 
    <groupId>javax.enterprise</groupId> 
    <artifactId>cdi-api</artifactId> 
    <version>1.2</version> 
    <scope>provided</scope> 
</dependency> 

<!-- Métodos uteis para manipulação de String, métodos e etc --> 
<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-lang3</artifactId> 
    <version>3.4</version> 
</dependency> 

<!-- PROVIDER JPA(HIBERNATE) --> 
<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <version>4.3.0.Final</version> 
</dependency> 

<!-- DEPENDENCIA MYSQL --> 
<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.44</version> 
</dependency> 

<!-- Manipulação de XML --> 
<dependency> 
    <groupId>jdom</groupId> 
    <artifactId>jdom</artifactId> 
    <version>1.1</version> 
</dependency> 

<dependency> 
    <groupId>br.ufes.inf.nemo</groupId> 
    <artifactId>jbutler-wp</artifactId> 
    <version>1.2.4</version> 
</dependency> 

<dependency> 
    <groupId>org.primefaces.themes</groupId> 
    <artifactId>bootstrap</artifactId> 
    <version>1.0.10</version> 
</dependency> 

回答

1

你只要有一點依賴污染。

修改你的依賴如下,我相信你會得到啓動和運行:

<!-- WildFly implements everything in this jar --> 
<dependency> 
    <groupId>javax</groupId> 
    <artifactId>javaee-api</artifactId> 
    <version>7.0</version> 
    <scope>provided</scope> 
</dependency> 

<!-- PrimeFaces --> 
<dependency> 
    <groupId>org.primefaces</groupId> 
    <artifactId>primefaces</artifactId> 
    <version>5.3</version> 
</dependency> 

<!-- Métodos uteis para manipulação de String, métodos e etc --> 
<dependency> 
    <groupId>org.apache.commons</groupId> 
    <artifactId>commons-lang3</artifactId> 
    <version>3.4</version> 
</dependency> 

<!-- Manipulação de XML --> 
<dependency> 
    <groupId>jdom</groupId> 
    <artifactId>jdom</artifactId> 
    <version>1.1</version> 
</dependency> 

<dependency> 
    <groupId>br.ufes.inf.nemo</groupId> 
    <artifactId>jbutler-wp</artifactId> 
    <version>1.2.4</version> 
</dependency> 

<dependency> 
    <groupId>org.primefaces.themes</groupId> 
    <artifactId>bootstrap</artifactId> 
    <version>1.0.10</version> 
</dependency> 
+0

冗餘去看看我的教授談話關於這個問題,他給了我完全相同的答案,我是雙重導入幾個依賴關係,非常感謝@Steve C,讓它成爲未來搜索的參考。 – Paternostro

1

添加<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>到persistence.xml中。

你也應該從org.hibernate.ejb.HibernatePersistence遷移的是Hibernate 4.3不贊成以org.hibernate.jpa.HibernatePersistenceProvider

+0

'hibernate.dialect'是在一個正確配置的JPA 2.x的應用 –