11 Replies Latest reply on Oct 1, 2012 4:17 AM by Bartosz Majsak

    Arquillian with Hibernate ClassNotFoundException

    Milan Milosevic Newbie

      Hi, (again )

      My project is configured as I posted here.

      I use Hibernate persistence framework. When I start arquillian test, I get ClassNotFoundException:

       

      java.lang.RuntimeException: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

                at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:180)

                at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)

                at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)

                at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)

                at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)

                at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)

                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)

                at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:214)

                at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:207)

                at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:323)

                at org.glassfish.admin.rest.resources.TemplateListOfResource.post(TemplateListOfResource.java:180)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:601)

                at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)

                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)

                at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)

                at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)

                at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)

                at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer._service(GrizzlyContainer.java:182)

                at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer.service(GrizzlyContainer.java:147)

                at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:148)

                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)

                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)

                at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)

                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)

                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)

                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)

                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)

                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

                at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

                at java.lang.Thread.run(Thread.java:722)

      Caused by: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)

                at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:174)

                ... 59 more

       

       

      SEVERE: Exception while preparing the app : java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

      java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1359)

                at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:174)

                at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:120)

                at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:224)

                at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:495)

                at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:233)

                at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:871)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:410)

                at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:240)

                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:389)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:348)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:363)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1085)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1200(CommandRunnerImpl.java:95)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1291)

                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1259)

                at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:214)

                at org.glassfish.admin.rest.ResourceUtil.runCommand(ResourceUtil.java:207)

                at org.glassfish.admin.rest.resources.TemplateListOfResource.createResource(TemplateListOfResource.java:323)

                at org.glassfish.admin.rest.resources.TemplateListOfResource.post(TemplateListOfResource.java:180)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.lang.reflect.Method.invoke(Method.java:601)

                at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)

                at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)

                at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)

                at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)

                at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.SubLocatorRule.accept(SubLocatorRule.java:134)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)

                at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

                at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)

                at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)

                at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)

                at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer._service(GrizzlyContainer.java:182)

                at com.sun.jersey.server.impl.container.grizzly.GrizzlyContainer.service(GrizzlyContainer.java:147)

                at org.glassfish.admin.rest.adapter.RestAdapter.service(RestAdapter.java:148)

                at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:179)

                at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:117)

                at com.sun.enterprise.v3.services.impl.ContainerMapper$Hk2DispatcherCallable.call(ContainerMapper.java:354)

                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)

                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)

                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)

                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)

                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)

                at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)

                at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)

                at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)

                at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)

                at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)

                at com.sun.grizzly.ContextTask.run(ContextTask.java:71)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)

                at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)

                at java.lang.Thread.run(Thread.java:722)

       

      I tried to add following dependency to my pom.xml, but it still throws the same exception.

      <dependency>

                  <groupId>org.hibernate</groupId>

                  <artifactId>hibernate-entitymanager</artifactId>

                  <version>4.1.7.Final</version>

                  <scope>test</scope>

      </dependency>

       

      Without test goal project builds and works fine.

      I just saw that I posted test-persistence.xml twice, and I forgot to post src/test/resources/persistence.xml. So here it is:

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

        <persistence-unit name="A-PU" transaction-type="JTA">

          <provider>org.hibernate.ejb.HibernatePersistence</provider>

          <jta-data-source>jdbc/rootApp</jta-data-source>

          <class>com.codenious.root.ejb.ejbentity.Car</class>

          <class>com.codenious.root.ejb.ejbentity.Renter</class>

          <class>com.codenious.root.ejb.ejbentity.UserGroup</class>

          <class>com.codenious.root.ejb.ejbentity.Game</class>

          <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

          <validation-mode>CALLBACK</validation-mode>

          <properties>

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

          </properties>

        </persistence-unit>

      </persistence>

        • 1. Re: Arquillian with Hibernate ClassNotFoundException
          Bartosz Majsak Master

          How does your shrinkwrap packaging look like? Maybe you need to add Hibernate dependencies to your test deployment? As far as I know GF is shipped with Eclipse Link, so you need to provide Hibernate one way or the other.

           

          Cheers,

          Bartosz

          • 2. Re: Arquillian with Hibernate ClassNotFoundException
            Milan Milosevic Newbie

            It sounds like it could be it. I changed Eclipse Link with Hibernate and it works fine. But when I try to test it with arquillian, it seems that test deployment is missing Hibernate artifacts.

            Here is the ShrinkWrap package:

               @Deployment

                public static Archive<?> createDeployment() {

                    JavaArchive jar = ShrinkWrap.create(JavaArchive.class)

                            .addPackage(Game.class.getPackage())

                            .addAsManifestResource("test-persistence.xml", "persistence.xml")

                            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

             

                    return jar;

                }

             

            I tried this way to add org.hibernate:hibernate-entitymanager to test deployment, but I get exclamation marks from NetBeans.

             

             

            MavenDependencyResolver resolver = DependencyResolvers

                            .use(MavenDependencyResolver.class) // exclamation mark on this line (method use in class DependencyResolvers cannot be applied to given types)

                            .loadMetadataFromPom("pom.xml");

             

                    JavaArchive jar = ShrinkWrap.create(JavaArchive.class)

                            .addAsLibraries(resolver.artifact("org.hibernate:hibernate-entitymanager:4.1.7.Final").resolveAsFiles()) // exclamation mark on this line (cannot find symbol: method                                                                                                                                //resolveAsFiles())

                            .addPackage(Game.class.getPackage())

                            .addAsManifestResource("test-persistence.xml", "persistence.xml")

                            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

            • 3. Re: Arquillian with Hibernate ClassNotFoundException
              Bartosz Majsak Master

              Can you share the full project? [zipped or sth]

              • 4. Re: Arquillian with Hibernate ClassNotFoundException
                Milan Milosevic Newbie

                I'm sorry, but I cannot share full project. I used the same examples for entity class and for test class as in this guide, but I incorporeted them in my project. So majority of the files are the same, except of the fact that I use Hibernate, remote Glassfish and postgresql db.

                 

                Here are the files:

                 

                Game.java:

                @Entity

                public class Game implements Serializable {

                    private Long id;

                    private String title;

                 

                    public Game() {}

                 

                    public Game(String title) {

                        this.title = title;

                    }

                 

                    @Id @GeneratedValue

                    public Long getId() {

                        return id;

                    }

                 

                    public void setId(Long id) {

                        this.id = id;

                    }

                 

                    @NotNull

                    @Size(min = 3, max = 50)

                    public String getTitle() {

                        return title;

                    }

                 

                    public void setTitle(String title) {

                        this.title = title;

                    }

                 

                    @Override

                    public String toString() {

                        return "Game@" + hashCode() +

                            "[id = " + id + "; title = " + title + "]";

                    }

                }

                 

                 

                GamePersistenceTest.java:

                @RunWith(Arquillian.class)

                public class GamePersistenceTest {

                 

                 

                    @Deployment

                    public static Archive<?> createDeployment() {

                      // You can use war packaging...

                        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")

                                .addPackage(Game.class.getPackage())

                                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")

                                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

                 

                 

                        // or jar packaging...

                        JavaArchive jar = ShrinkWrap.create(JavaArchive.class)

                                .addPackage(Game.class.getPackage())

                                .addAsManifestResource("test-persistence.xml", "persistence.xml")

                                .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

                 

                 

                        // choose your packaging here

                        return jar;

                    }

                    private static final String[] GAME_TITLES = {

                        "Super Mario Brothers",

                        "Mario Kart",

                        "F-Zero"

                    };

                    @PersistenceContext

                    EntityManager em;

                    @Inject

                    UserTransaction utx;

                 

                 

                    @Before

                    public void preparePersistenceTest() throws Exception {

                        clearData();

                        insertData();

                        startTransaction();

                    }

                 

                 

                    private void clearData() throws Exception {

                        utx.begin();

                        em.joinTransaction();

                        System.out.println("Dumping old records...");

                        em.createQuery("delete from Game").executeUpdate();

                        utx.commit();

                    }

                 

                 

                    private void insertData() throws Exception {

                        utx.begin();

                        em.joinTransaction();

                        System.out.println("Inserting records...");

                        for (String title : GAME_TITLES) {

                            Game game = new Game(title);

                            em.persist(game);

                        }

                        utx.commit();

                        // reset the persistence context (cache)

                        em.clear();

                    }

                 

                 

                    private void startTransaction() throws Exception {

                        utx.begin();

                        em.joinTransaction();

                    }

                 

                 

                    @After

                    public void commitTransaction() throws Exception {

                        utx.commit();

                    }

                 

                 

                    @Test

                    public void shouldFindAllGamesUsingJpqlQuery() throws Exception {

                        // given

                        String fetchingAllGamesInJpql = "select g from Game g order by g.id";

                 

                 

                        // when

                        System.out.println("Selecting (using JPQL)...");

                        List<Game> games = em.createQuery(fetchingAllGamesInJpql, Game.class).getResultList();

                 

                 

                        // then

                        System.out.println("Found " + games.size() + " games (using JPQL):");

                        assertContainsAllGames(games);

                    }

                 

                 

                    private static void assertContainsAllGames(Collection<Game> retrievedGames) {

                        Assert.assertEquals(GAME_TITLES.length, retrievedGames.size());

                        final Set<String> retrievedGameTitles = new HashSet<String>();

                        for (Game game : retrievedGames) {

                            System.out.println("* " + game);

                            retrievedGameTitles.add(game.getTitle());

                        }

                        Assert.assertTrue(retrievedGameTitles.containsAll(Arrays.asList(GAME_TITLES)));

                    }

                }


                src/main/resources/persistence.xml:

                <?xml version="1.0" encoding="UTF-8"?>

                <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

                  <persistence-unit name="A-PU" transaction-type="JTA">

                    <provider>org.hibernate.ejb.HibernatePersistence</provider>

                    <jta-data-source>jdbc/rootApp</jta-data-source>

                    <class>com.codenious.root.ejb.ejbentity.Car</class>

                    <class>com.codenious.root.ejb.ejbentity.Renter</class>

                    <class>com.codenious.root.ejb.ejbentity.UserGroup</class>

                    <class>com.codenious.root.ejb.ejbentity.Game</class>

                    <exclude-unlisted-classes>false</exclude-unlisted-classes>

                    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

                    <validation-mode>CALLBACK</validation-mode>

                    <properties>

                      <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>

                      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

                    </properties>

                  </persistence-unit>

                </persistence>

                 

                src/test/resources/arquillian.xml:

                <?xml version="1.0" encoding="UTF-8"?>

                <arquillian xmlns="http://jboss.org/schema/arquillian"

                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                    xsi:schemaLocation="

                        http://jboss.org/schema/arquillian

                        http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

                   

                    <container qualifier="glassfish-remote" default="true" >

                        <configuration>

                            <property name="glassFishHome">/opt/app/glassfish-3.1.2.2</property>

                            <property name="adminHost">localhost</property>

                            <property name="adminPort">8888</property>

                            <property name="resourcesXml">

                                src/test/resources-glassfish-remote/glassfish-resources.xml

                            </property>

                        </configuration>

                    </container>

                </arquillian>

                 

                src/test/resources-glassfish-remote/test-persistence.xml:

                <?xml version="1.0" encoding="UTF-8"?>

                <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">

                  <persistence-unit name="test" transaction-type="JTA">

                    <provider>org.hibernate.ejb.HibernatePersistence</provider>

                    <jta-data-source>jdbc/rootApp</jta-data-source>

                    <class>com.codenious.root.ejb.ejbentity.Car</class>

                    <class>com.codenious.root.ejb.ejbentity.Renter</class>

                    <class>com.codenious.root.ejb.ejbentity.UserGroup</class>

                    <class>com.codenious.root.ejb.ejbentity.Game</class>

                    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

                    <validation-mode>CALLBACK</validation-mode>

                    <properties>

                      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

                      <property name="hibernate.current_session_context_class" value="jta"/>

                      <property name="hibernate.show_sql" value="true"/>

                      <property name="hibernate.format_sql" value="true"/>

                      <property name="hibernate.default_schema" value="public"/>

                      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

                    </properties>

                  </persistence-unit>

                </persistence>

                 

                pom.xml (relevant part):

                 

                    <dependencyManagement>

                        <dependencies>

                            <dependency>

                                <groupId>org.jboss.arquillian</groupId>

                                <artifactId>arquillian-bom</artifactId>

                                <version>1.0.0.Final</version>

                                <scope>import</scope>

                                <type>pom</type>

                            </dependency>

                        </dependencies>

                    </dependencyManagement>

                 

                 

                    <dependencies>

                        <dependency>

                            <groupId>org.testng</groupId>

                            <artifactId>testng</artifactId>

                            <version>6.5.2</version>

                            <scope>test</scope>

                        </dependency>

                 

                        <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-jpamodelgen</artifactId>

                            <version>1.2.0.Final</version>

                            <scope>provided</scope>

                        </dependency>

                 

                        <dependency>

                            <groupId>junit</groupId>

                            <artifactId>junit</artifactId>

                            <version>4.8.2</version>

                            <scope>test</scope>

                        </dependency>

                 

                        <dependency>

                            <groupId>org.hibernate</groupId>

                            <artifactId>hibernate-core</artifactId>

                            <version>4.1.6.Final</version>

                        </dependency>

                 

                        <dependency>

                            <groupId>org.slf4j</groupId>

                            <artifactId>slf4j-simple</artifactId>

                            <version>1.6.6</version>

                        </dependency>

                 

                        <dependency>

                            <groupId>javassist</groupId>

                            <artifactId>javassist</artifactId>

                            <version>3.12.1.GA</version>

                        </dependency>

                 

                        <dependency>

                            <groupId>org.jboss.arquillian.junit</groupId>

                            <artifactId>arquillian-junit-container</artifactId>

                            <scope>test</scope>

                        </dependency>

                 

                    </dependencies>

                 

                <build>

                        <plugins>

                            <plugin>

                                <groupId>org.apache.maven.plugins</groupId>

                                <artifactId>maven-compiler-plugin</artifactId>

                                <version>2.3.2</version>

                                <configuration>

                                    <source>1.6</source>

                                    <target>1.6</target>

                                    <compilerArguments>

                                        <endorseddirs>${endorsed.dir}</endorseddirs>

                                    </compilerArguments>

                                </configuration>

                            </plugin>

                            <plugin>

                                <groupId>org.apache.maven.plugins</groupId>

                                <artifactId>maven-ejb-plugin</artifactId>

                                <version>2.3</version>

                                <configuration>

                                    <ejbVersion>3.1</ejbVersion>

                                </configuration>

                            </plugin>

                            <plugin>

                                <groupId>org.apache.maven.plugins</groupId>

                                <artifactId>maven-dependency-plugin</artifactId>

                                <version>2.1</version>

                                <executions>

                                    <execution>

                                        <phase>validate</phase>

                                        <goals>

                                            <goal>copy</goal>

                                        </goals>

                                        <configuration>

                                            <outputDirectory>${endorsed.dir}</outputDirectory>

                                            <silent>true</silent>

                                            <artifactItems>

                                                <artifactItem>

                                                    <groupId>javax</groupId>

                                                    <artifactId>javaee-endorsed-api</artifactId>

                                                    <version>6.0</version>

                                                    <type>jar</type>

                                                </artifactItem>

                                            </artifactItems>

                                        </configuration>

                                    </execution>

                                </executions>

                            </plugin>

                            <plugin>

                                <artifactId>maven-surefire-plugin</artifactId>

                                <version>2.12</version>

                            </plugin>

                        </plugins>

                    </build>

                 

                <profiles>

                        <profile>         

                            <id>arquillian-glassfish-remote</id>

                            <dependencies>

                                <dependency>

                                    <groupId>org.jboss.spec</groupId>

                                    <artifactId>jboss-javaee-web-6.0</artifactId>

                                    <version>3.0.0.Final</version>

                                    <type>pom</type>

                                    <scope>provided</scope>

                                    <exclusions>

                                        <exclusion>

                                            <groupId>xalan</groupId>

                                            <artifactId>xalan</artifactId>

                                        </exclusion>

                                    </exclusions>

                                </dependency>

                                <dependency>

                                    <groupId>org.jboss.arquillian.container</groupId>

                                    <artifactId>arquillian-glassfish-remote-3.1</artifactId>

                                    <version>1.0.0.CR3</version>

                                    <scope>test</scope>

                                </dependency>

                                <dependency>

                                    <groupId>postgresql</groupId>

                                    <artifactId>postgresql</artifactId>

                                    <version>9.1-901.jdbc4</version>

                                    <scope>test</scope>

                                </dependency>              

                            </dependencies>         

                            <build>

                                <testResources>

                                    <testResource>

                                        <directory>src/test/resources</directory>

                                    </testResource>

                                    <testResource>

                                        <directory>src/test/resources-glassfish-remote</directory>

                                    </testResource>

                                </testResources>

                            </build>

                        </profile>

                </profiles>

                • 5. Re: Arquillian with Hibernate ClassNotFoundException
                  Bartosz Majsak Master

                  Please update Arquillian to 1.0.2.Final and let me know if you still have compilation errors form Maven Resolver from shrinkwrap descriptors. I also don't see in the POM that you include maven-resolver-impl, have a look here: https://github.com/bartoszmajsak/Beer-Advisor/blob/master/web/pom.xml#L110

                  • 6. Re: Arquillian with Hibernate ClassNotFoundException
                    Milan Milosevic Newbie

                    I changed arquillian-bom version:

                    <dependencyManagement>

                            <dependencies>

                                <dependency>

                                    <groupId>org.jboss.arquillian</groupId>

                                    <artifactId>arquillian-bom</artifactId>

                                    <version>1.0.2.Final</version>

                                    <scope>import</scope>

                                    <type>pom</type>

                                </dependency>

                            </dependencies>

                        </dependencyManagement>

                     

                    and added maven-resolver-impl.

                     

                    The first error is gone, but the second is still there. However, there is no error in WebArchive in resolveAsFiles() method.

                     

                    MavenDependencyResolver resolver = DependencyResolvers

                                    .use(MavenDependencyResolver.class)

                                    .loadMetadataFromPom("pom.xml");

                     

                            // You can use war packaging...

                            WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")

                                    .addPackage(Game.class.getPackage())

                                    .addAsLibraries(resolver.artifact("org.hibernate:hibernate-entitymanager:4.1.6.Final").resolveAsFiles()) // NO ERROR

                                    .addAsResource("test-persistence.xml", "META-INF/persistence.xml")

                                    .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

                     

                            // or jar packaging...

                            JavaArchive jar = ShrinkWrap.create(JavaArchive.class)

                                    .addPackage(Game.class.getPackage())

                                    .addAsLibraries(resolver.artifact("org.hibernate:hibernate-entitymanager:4.1.6.Final").resolveAsFiles()) // ERROR

                                    .addAsManifestResource("test-persistence.xml", "persistence.xml")

                                    .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

                     

                     

                            // choose your packaging here

                            return jar;

                    • 7. Re: Arquillian with Hibernate ClassNotFoundException
                      Bartosz Majsak Master

                      JarArchive is not LibraryContainer, therefore you can't add libraries to it. I would propose to go with WAR deployment. If you really need JAR then merge your archive with fetched dependencies.

                      • 8. Re: Arquillian with Hibernate ClassNotFoundException
                        Milan Milosevic Newbie

                        Yes, I forgot about that.

                         

                        I added org.hibernate:hibernate-core to test deployment, but I still get the same exception (ClassNotFoundException org.hibernate.ejb.HibernatePersistence) when running tests.

                         

                        Here is how I added that hibernate artifact:

                        WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war")

                                        .addPackage(Game.class.getPackage())

                                        .addAsLibraries(resolver.artifact("org.hibernate:hibernate-core:4.1.7.Final").resolveAsFiles())

                                        .addAsResource("test-persistence.xml", "META-INF/persistence.xml")

                                        .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

                         

                        Btw, thank you for helping so far.

                        • 9. Re: Arquillian with Hibernate ClassNotFoundException
                          Bartosz Majsak Master

                          Shouldn't it be in hibernate-entitymanager, not core?

                          • 10. Re: Arquillian with Hibernate ClassNotFoundException
                            Milan Milosevic Newbie

                            I tried that, but it didn't work.

                            However, I switched back to EclipseLink and the tests are running fine.

                            I will try again with Hibernate later. For now, these settings will do.

                            Tnx for helping me.

                            • 11. Re: Arquillian with Hibernate ClassNotFoundException
                              Bartosz Majsak Master

                              I think it's more about how to deploy an app in GF based on Hibernate as JPA provider, not really an arquillian issue.