当我使用 MySQL 后端时,我有一个完美运行的测试。
持久性.xml:
<persistence-unit name="pu">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/mysqlTM</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
但是,当我按如下方式切换到 H2 时:
持久性.xml
<persistence-unit name="pu">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="true" />
</properties>
</persistence-unit>
使用股票 JBoss 7.1 安装中定义的标准数据源,我得到以下异常:
Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
谷歌帮助不大。我宁愿使用 H2 进行测试,只是为了加快测试过程。
提前感谢您的任何帮助,