2

我之前没有部署在 jboss 应用服务器上。尝试在openshift. 我正在使用SpringJPA 2.0

我的applicationContext.xml

<jee:jndi-lookup id="dataSource" jndi-name="java:jboss/datasources/MysqlDS" resource-ref="true" />

我的 standalone.xml

<datasource jndi-name="java:jboss/datasources/MysqlDS" enabled="${mysql.enabled}" use-java-context="true" pool-name="MysqlDS">
                    <connection-url>jdbc:mysql://${env.OPENSHIFT_DB_HOST}:${env.OPENSHIFT_DB_PORT}/${env.OPENSHIFT_APP_NAME}</connection-url>
                    <driver>mysql</driver>
                    <security>
                      <user-name>${env.OPENSHIFT_DB_USERNAME}</user-name>
                      <password>${env.OPENSHIFT_DB_PASSWORD}</password>
                    </security>
                </datasource>
                <drivers>
                    <driver name="mysql" module="com.mysql.jdbc">
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
                </drivers>

错误

2012/07/12 09:00:36,714 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH000204: Processing PersistenceUnitInfo [
    name: tentacleSpotPU
   ...]
2012/07/12 09:00:37,118 WARN  [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] (MSC service thread 1-2) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections
2012/07/12 09:00:37,139 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.persistenceunit."ROOT.war#tentacleSpotPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ROOT.war#tentacleSpotPU": Failed to start service
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.6.0_24]
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.6.0_24]
   at java.lang.Thread.run(Thread.java:679) [rt.jar:1.6.0_24]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: tentacleSpotPU] Unable to build EntityManagerFactory
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
    at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
   at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
    ... 3 more
Caused by: org.hibernate.HibernateException: Connection cannot be null when 'hibernate.dialect' not set
   at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:97)
 at org.hibernate.service.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:67)
 at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:176)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
  at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2270)
  at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2266)
  at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1735)
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84)
   at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904)
   ... 9 more

2012/07/12 09:00:37,309 ERROR [org.jboss.as] (MSC service thread 1-3) JBAS015875: JBoss AS 7.1.0.Final "Thunder" started (with errors) in 75169ms - Started 401 of 720 services (203 services failed or missing dependencies, 113 services are passive or on-demand)
2012/07/12 09:00:37,440 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "ROOT.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\": Failed to start service"}}
2012/07/12 09:00:38,574 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment ROOT.war in 1131ms
2012/07/12 09:00:38,576 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.persistenceunit."ROOT.war#tentacleSpotPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."ROOT.war#tentacleSpotPU": Failed to start service

2012/07/12 09:00:38,609 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"ROOT.war#tentacleSpotPU\": Failed to start service"}}}}

我需要做什么来解决这个问题?

4

3 回答 3

0

您应该尝试设置 hibernate.dialect 属性以允许 JBoss 在没有连接的情况下加载持久性上下文(它可以使用连接来检测方言)。它将等待从应用程序获取连接(在您的情况下为 Spring)。

您可以在 persistence.xml 中设置它,或者应该可以在放置在类路径根目录中的 hibernate.properties 中

于 2012-07-13T17:29:39.337 回答
0

你的项目设置如何?项目是否使用 jboss 7.1.0 Final 在本地运行?我使用一个persistence.xml 文件,它为我的JPA 2.0 配置定义了我的EntityManagerFactory 和hibernate.dialect。位于我的 META-INF 目录中。这就是我在我的项目中设置它的方式。

<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_2_0.xsd"
version="2.0">
<persistence-unit name="userpersistence" transaction-type="RESOURCE_LOCAL">
    <provider>
        org.hibernate.ejb.HibernatePersistence
    </provider>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/acctdatabase"/>
        <property name="hibernate.connection.username" value="acct-user"/>
        <property name="hibernate.connection.password" value="password"/>
    </properties>
</persistence-unit>

于 2012-07-12T18:40:58.127 回答
0

我得到了同样的例外。3-4 天后,我意识到我的 persistence.xml 的位置不正确。我有使用 EJB、JSF、MAVEN、MYSQL 的 EAR Web 应用程序。因此,在我的 Eclipse 中,我有 ejb 项目、web 项目、ear 项目和 main 项目。我正在更新 EJB 项目下 META-INF 文件夹中的persistance.xml 文件。但是,我忘记在 JPA 内容下的 Web 项目中更新相同的内容。因此,您将在 Web 项目的 META-INF 文件夹下找到相同的 persistence.xml 文件。默认情况下,unit-name 将是“project-name-web”和类。因此,请根据您在此处提到的相同更新该名称,包括 jta-datasource 到属性。它应该可以工作。我的工作正常。最后唷!

于 2015-03-23T16:48:02.663 回答