如果您尝试使用独立连接进行连接,即
<persistence-unit name="justshop-pu" transaction-type="RESOURCE_LOCAL">.
这可能是由于:
<property name="hibernate.connection.URL" value="false"/>
使用
<property name="hibernate.connection.url" value="false"/>
相反。区分大小写。
或者
配置数据源:
如果您在持久性单元中使用 JTA 作为事务类型,并且由于您尝试从 EJB 进行连接,该 EJB 是容器管理的上下文,因此它将默认为 JTA 事务。您需要配置数据源连接。
这些是在 JBoss 7.1 中用于 mysql 数据源配置的相同步骤:
<datasource jndi-name="java:jboss/datasources/ExpenseDS" pool-name="ExpenseDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost/expense</connection-url>
<driver>com.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>
</pool>
<security>
<user-name>username</user-name>
<password>pwd</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
- 还在standalone.xml中添加驱动入口,如下所示:
<driver name="com.mysql" module="com.mysql">
<driver-class>com.mysql.jdbc.Driver</driver-class>
<xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
</driver>
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<module xmlns="urn:jboss:module:1.1" name="com.mysql">
<resources>
<resource-root path="mysql-connector-java-5.1.31.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
- 将它与 mysql 驱动程序 jar 一起作为模块放入 jboss。在jboss的modules中创建一个module文件夹:
- 例如:对于 mysql,因为我们将模块作为 com.mysql,我们将创建文件夹 com/mysql 和另一个文件夹 main,并将驱动程序类和 module.xml 放在“com/mysql/main”中(请参阅 h2database 配置,如果你很困惑)