Reputation: 439
I´m trying to run our JPA Unit tests with arquillian- with an embedded wildfly. So far, i got the following steps working when i do a clean&build on project:
Now my problem: I´m getting the following exception, when i call a .create() or .delete() method on entitymanager inside my unit tests:
Caused by: javax.persistence.TransactionRequiredException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
These are the important dependencies of my pom.xml:
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.7.Final</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.test</groupId>
<artifactId>arquillian-test-spi</artifactId>
<version>1.1.7.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.1.7.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-embedded</artifactId>
<version>8.2.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-embedded</artifactId>
<version>8.2.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-depchain</artifactId>
<version>2.1.1</version>
<scope>test</scope>
<type>pom</type>
</dependency>
</dependencies>
<!-- Plugins -->
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>8.2.0.Final</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-db-driver</id>
<phase>process-test-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.microsoft</groupId>
<artifactId>sqljdbc</artifactId>
<version>4.0.2206.100</version>
<outputDirectory>target/wildfly-8.2.0.Final/standalone/deployments</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>datasource</id>
<phase>package</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources,data-source=tests</address>
<resources>
<resource>
<properties>
<connection-url>jdbc:sqlserver://SERVERADRESS_CENSORED;instanceName=web;databaseName=TMCDB</connection-url>
<jndi-name>java:jdbc/TMCDB</jndi-name>
<enabled>true</enabled>
<enable>true</enable>
<user-name>USER_CENSORED</user-name>
<password>PW_CENSORED</password>
<driver-name>sqljdbc-4.0.2206.100.jar</driver-name>
<use-ccm>false</use-ccm>
</properties>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Inside my persistence.xml, i´ve set the transaction-type="JTA".
And here´s the part, where the .war file gets created by arquillian/shrinkwrap. This stuff is annotated with the @Deployment tag of Arquillian:
PomEquippedResolveStage loadPomFromFile = Maven.resolver().loadPomFromFile("pom.xml");
File[] asFile = loadPomFromFile.importRuntimeAndTestDependencies().resolve().withTransitivity().asFile();
//MavenStrategyStage asFile = loadPomFromFile.importRuntimeAndTestDependencies().resolve();
WebArchive webArchive = ShrinkWrap.create(WebArchive.class)
.addAsLibraries(asFile)
.addPackages(true, "de.companyXYZ")
.addPackages(true, "org.springframework.beans.factory.config")
// Adding persistence unit
.addAsResource("test-persistence.xml", "META-INF/persistence.xml")
// Add ms-sql driver for the embedded wildfly
.addAsWebInfResource("wildfly-ds-driver.xml")
// Add datasource for the embedded wildfly
.addAsWebInfResource("wildfly-ds.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
webArchive.as(ZipExporter.class).exportTo(new File("./target/test-package.war"), true);
So, can anybody help me with this problem? I don´t understand why i´m getting this Exception- cause the wildfly should do the transaction management- that´s what i expect of him...
Upvotes: 2
Views: 2379
Reputation: 61
I add, and that solves my issues with transactions
import org.jboss.arquillian.transaction.api.annotation.Transactional;
@Transactional
Upvotes: 5