1

I have a problem with running EJB tests with Arquillian in Wildfly Swarm, it is related to Hibernate and this question: wildfly 10: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory

The error:

ERROR [stderr] (main) Caused by: java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.persistenceunit.\"adaee1b1-6c6b-4f9b-834a-ea36333986b8.jar#AP\""],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined} ERROR [stderr] (main) at org.wildfly.swarm.container.runtime.RuntimeDeployer.deploy(RuntimeDeployer.java:273)

I am using Hibernate and JPA and solved this when running Wildfly Swarm by setting <scope>provided</scope> to all Hibernate depedencies. This doesn't work when runnings tests in Arquillian however.

ServiceTest.java

@RunWith(Arquillian.class)
public class ServiceTest {
    @EJB
    private TestService testService;

    @Deployment
    public static Archive<?> createDeployment() throws Exception {
        return new ArchiveBuilder().buildArchive();
    }

    @Test
    public void testService() {
        testService.test();
    }
}

ArchiveBuilder.java

public class ArchiveBuilder {
    public Archive<?> buildArchive() throws Exception {
        final JARArchive ejbArchive = ShrinkWrap.create(JARArchive.class);
        ejbArchive.addClass(AdapterService.class);

        final List<JavaArchive> artifacts = ArtifactLookup.get().allArtifacts(new String[]{"org.wildfly.swarm"});

        for (final JavaArchive javaArchive : artifacts) {
            ejbArchive.merge(javaArchive);
        }

        return ejbArchive;
    }
}

ArchiveBuilder is taken from this post: https://dzone.com/articles/testing-ejbs-with-swarm-and-arquillian

pom.xml dependencies

<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>cdi</artifactId>
    <version>2017.5.0</version>
</dependency>

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>ejb</artifactId>
    <version>2017.5.0</version>
</dependency>

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jpa</artifactId>
    <version>2017.5.0</version>
</dependency>

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs</artifactId>
    <version>2017.5.0</version>
</dependency>

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.4.195</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.2.2.Final</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.10.Final</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-c3p0</artifactId>
    <version>5.2.10.Final</version>
    <scope>provided</scope>
</dependency>

If I modify the Hibernate dependency to remove dom4j.dom4j:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.2.10.Final</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

I get this instead:

ERROR [stderr] (main) Caused by: org.wildfly.swarm.container.DeploymentException: WFSWARM0004: Deployment failed: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"7d32cda0-83d2-47d3-8066-ae1f56899801.jar#AP\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"7d32cda0-83d2-47d3-8066-ae1f56899801.jar#AP\": javax.persistence.PersistenceException: [PersistenceUnit: AP] Unable to build Hibernate SessionFactory ERROR [stderr] (main) Caused by: javax.persistence.PersistenceException: [PersistenceUnit: AP] Unable to build Hibernate SessionFactory ERROR [stderr] (main) Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister ERROR [stderr] (main) Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer] ERROR [stderr] (main) Caused by: java.lang.reflect.InvocationTargetException ERROR [stderr] (main) Caused by: java.lang.RuntimeException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy ERROR [stderr] (main) Caused by: javassist.CannotCompileException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy ERROR [stderr] (main) Caused by: java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy ERROR [stderr] (main) Caused by: java.lang.ClassNotFoundException: org.hibernate.proxy.HibernateProxy from [Module \"org.picketbox:main\" from BootModuleLoader@22555ebf for finders [BootstrapClasspathModuleFinder, BootstrapModuleFinder(org.wildfly.swarm.bootstrap:main), ClasspathModuleFinder, ContainerModuleFinder(swarm.container:main), ApplicationModuleFinder(swarm.application:main), org.wildfly.swarm.bootstrap.modules.DynamicModuleFinder@36ebc363]]"},"WFLYCTL0412: Required services that are not installed:" => ["jboss.persistenceunit.\"7d32cda0-83d2-47d3-8066-ae1f56899801.jar#AP\""],"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined}

Jonas
  • 343
  • 1
  • 4
  • 15
  • The Hibernate classes should be on the compile classpath by virtue of the `jpa` dependency, so you shouldn't need to add them yourself. If not, then we probably need to fix something. Can you raise an issue: https://issues.jboss.org/browse/SWARM – Ken May 19 '17 at 20:17
  • It seems to be because it is a multi-module Maven project, I refactored it into a standard war project and it works. I'll create a reproducable project and raise an issue. – Jonas May 22 '17 at 18:44

0 Answers0