I have a test that runs perfectly when I use a MySQL Backend.
persistence.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>
However, when I switch to H2 as follows:
persistence.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>
using the standard datasource as defined in the stock JBoss 7.1 install and I get the following exception:
Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
Google has been of little help. I would prefer to use H2 for testing merely to speed up the testing process.
Thanks in advance for any assistance,
Answering the question so it can be closed.
As it turns out, the error message with regards to transactions is a red-herring. The error was caused due to the different ways in which MySQL and H2 handle case sensitivity in queries.
Updating the queries to be case sensitive solved the issue.