在JBoss上部署Hibernate应用程序时出错 - 没有找到适合jdbc的驱动程序 [英] Error deploying Hibernate app on JBoss - No suitable driver found for jdbc
问题描述
我有一个Spring / Hibernate Web应用程序(目前在Tomcat上正常工作),我试图部署到JBoss 7.1 AS。
应用程序全部正确启动,但是如果我将Hibernate持久性设置设置为创建表,那么在启动时会出现错误。
在tomcat上工作的持久性XML如下所示:
< persistence-unit name =persistenceUnit
transaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< property name =hibernate.hbm2ddl.autovalue =create/>
< property name =hibernate.ejb.naming_strategyvalue =org.hibernate.cfg.ImprovedNamingStrategy/>
< property name =hibernate.show_sqlvalue =false/>
< / properties>
< / persistence-unit>
当我将这个PU移到JBoss时,我开始出现错误,指出它不能连接到DB: / p>
20:41:18,312 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport](MSC service thread 1-5)HHH000231:模式导出不成功:java.lang.UnsupportedOperationException:应用程序必须提供JDBC连接
我使用Google搜索并找到建议我通过在持久性配置中添加hibernate连接详细信息来更新我的PU:
< persistence-unit name = persistenceUnit
transaction-type =RESOURCE_LOCAL>
< provider> org.hibernate.ejb.HibernatePersistence< / provider>
<属性>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< property name =hibernate.hbm2ddl.autovalue =create/>
< property name =hibernate.ejb.naming_strategyvalue =org.hibernate.cfg.ImprovedNamingStrategy/>
< property name =hibernate.show_sqlvalue =false/>
< property name =hibernate.connection.usernamevalue =root/>
< property name =hibernate.connection.passwordvalue =root/>
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< / properties>
< / persistence-unit>
我已经完成了这项工作,不再发生用户错误,但是现在只是出现以下错误应用程序启动:
20:35:41,791 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport](MSC service thread 1- 8)HHH000231:模式导出失败:java.sql.SQLException:找不到合适的驱动程序:jdbc \:mysql\:// localhost\:3306 / socialcv $ b $ java.sql.DriverManager.getConnection(DriverManager .java:604)[rt.jar:1.7.0_03]
在java.sql.DriverManager.getConnection(DriverManager.java:190)[rt.jar:1.7.0_03]
在org.hibernate .service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173)[hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl .SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51)[hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool。 hbm2ddl.DatabaseExporter。< init>(DatabaseExporter.java:52)[hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.execute (SchemaExport.java:368)[hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:305)[ hibernate-core-4.0.1.Final.jar:4.0.1.Final]
在org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:294)[hibernate-core-4.0.1。 Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionFactoryImpl。< init>(SessionFactoryImpl.java:452)[hibernate-core-4.0.1.Final.jar:4.0.1 .final]
在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)[hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org。 hibernate.ejb.EntityManagerFactoryImpl。< init>(EntityManagerFactoryImpl.java:84)[hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory (的Ejb3配置.java:904)[hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
在org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889)[hibernate-entitymanager -4.0.1.Final.jar:4.0.1.Final]
在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)[hibernate-entitymanager-4.0.1.Final.jar:4.0 .1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)[jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final ]
在org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)[jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl $ StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl $ StartTask.run(ServiceControllerImpl.java:1746)
在java.util.concurrent.ThreadPoolExecutor .runWorker(ThreadPoolExecutor.java:1110)[rt.jar:1.7.0_03]
在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)[rt.jar:1.7.0_03]
at java.lang.Thread.run(Thread.java:722)[rt.jar:1.7.0_03]
有没有人遇到过这个问题或知道任何解决方案? 首先:您的数据库连接URL看起来不正确它应该可能是 jdbc:mysql:// localhost:3306 / socialcv
。
最好将MySQL驱动程序安装为模块,请参阅此处: https://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_module
然后使用standalone.xml使用该驱动程序定义数据源: p> < datasource jta =truejndi-name =java:jboss / datasources / YourDatasourceNamepool-name =AnotherName enabled =trueuse-java-context =trueuse-ccm =true>
< connection-url> jdbc:mysql:// localhost:3306 / socialcv< / connection-url>
< driver> mysql< / driver>
< transaction-isolation> TRANSACTION_READ_COMMITTED< / transaction-isolation>
< pool>
< min-pool-size> 10< / min-pool-size>
< max-pool-size> 100< / max-pool-size>
< prefill> true< / prefill>
< use-strict-min> false< / use-strict-min>
< flush-strategy> FailingConnectionOnly< / flush-strategy>
< / pool>
< security>
<用户名> hehe< /用户名>
<密码> hehehe< /密码>
< / security>
< / datasource>
<驱动程序>
...
< driver name =mysqlmodule =com.mysql>
< xa-datasource-class> com.mysql.jdbc.jdbc2.optional.MysqlXADataSource< / xa-datasource-class>
< / driver>
< / drivers>
在你的persistence.xml中不要使用 hibernate.connection。* 属性,改为使用:
<非-jta数据源> java:jboss /数据源/ YourDatasourceName< /非JTA数据源>
这是初始化整个事物的事实上的方法。注意,当使用
transaction-type =JTA
而不是
transaction-type =RESOURCE_LOCAL
您必须更改为
< JTA - 数据 - 源>的java:JBoss的/数据源/ YourDatasourceName< / JTA - 数据 - 源>
它可以为您提供CMT(容器管理的交易)。
I have a Spring/Hibernate web application (currently working fine on Tomcat) that I am attempting to deploy to JBoss 7.1 AS.
The application all starts correctly, but if I set the Hibernate Persistence settings to create tables then I get an error on startup.
My persistence XML that was working on tomcat is as follows:
<persistence-unit name="persistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
When I moved this PU to JBoss I started getting errors stating that it couldnt connect to the DB:
20:41:18,312 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-5) HHH000231: Schema export unsuccessful: java.lang.UnsupportedOperationException: The application must supply JDBC connections
I googled and found a suggestion that I update my PU as follows by adding the hibernate connection details in the persistence config:
<persistence-unit name="persistenceUnit"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="create" />
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.connection.url" value="jdbc\:mysql\://localhost\:3306/socialcv" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="root" />
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
</properties>
</persistence-unit>
I have done this, and no longer get the user errors, but now just get the following error on app startup:
20:35:41,791 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (MSC service thread 1-8) HHH000231: Schema export unsuccessful: java.sql.SQLException: No suitable driver found for jdbc\:mysql\://localhost\:3306/socialcv
at java.sql.DriverManager.getConnection(DriverManager.java:604) [rt.jar:1.7.0_03]
at java.sql.DriverManager.getConnection(DriverManager.java:190) [rt.jar:1.7.0_03]
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:173) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.DatabaseExporter.<init>(DatabaseExporter.java:52) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:368) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:305) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:294) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:452) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:84) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:904) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:889) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_03]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_03]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_03]
Has anyone come across this or know any solution?
First of all: your DB connection URL looks incorrect. It should probably be jdbc:mysql://localhost:3306/socialcv
.
Then:
Best install the MySQL driver as a module, see here: https://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_module
Then use standalone.xml to define a data source using that driver:
<datasource jta="true" jndi-name="java:jboss/datasources/YourDatasourceName" pool-name="AnotherName" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://localhost:3306/socialcv</connection-url>
<driver>mysql</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>10</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>hehe</user-name>
<password>hehehe</password>
</security>
</datasource>
<drivers>
...
<driver name="mysql" module="com.mysql">
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
</drivers>
In your persistence.xml don't use the hibernate.connection.*
properties, instead use:
<non-jta-data-source>java:jboss/datasources/YourDatasourceName</non-jta-data-source>
This is the de facto way to init the whole thing. Note, when using
transaction-type="JTA"
instead of
transaction-type="RESOURCE_LOCAL"
you have to change to
<jta-data-source>java:jboss/datasources/YourDatasourceName</jta-data-source>
which gives you CMT (container-managed transactions).
这篇关于在JBoss上部署Hibernate应用程序时出错 - 没有找到适合jdbc的驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!