TOMEE-3741 New Example and documentation JPA Hibernate 5 with arquillian
diff --git a/docs/tomee-and-hibernate.adoc b/docs/tomee-and-hibernate.adoc
index 5bc4d24..666b9a9 100644
--- a/docs/tomee-and-hibernate.adoc
+++ b/docs/tomee-and-hibernate.adoc
@@ -61,6 +61,11 @@
                 value="org.apache.openejb.hibernate.TransactionManagerLookup"/>
 ----
 
+For Hibernate 5 the following property needs to be explicitly added it either as system property or persistence unit.
+----
+<property name="tomee.jpa.factory.lazy" value="true"/>
+----
+
 == Server Configuration
 
 The default JPA provider can be changed at the server level to favor
@@ -86,8 +91,6 @@
 
 Jars needed for Hibernate 4.x:
 
-Add:
-
 * `<tomee-home>/lib/antlr-2.7.7.jar`
 * `<tomee-home>/lib/dom4j-1.6.1.jar`
 * `<tomee-home>/lib/hibernate-commons-annotations-4.0.1.Final.jar`
@@ -96,6 +99,20 @@
 * `<tomee-home>/lib/hibernate-validator-4.3.0.Final.jar`
 * `<tomee-home>/lib/jboss-logging-3.1.0.GA.jar`
 
+Jars needed for Hibernate 5.x:
+
+* `<tomee-home>/lib/antlr-2.7.7.jar`
+* `<tomee-home>/lib/dom4j-1.6.1.jar`
+* `<tomee-home>/lib/hibernate-commons-annotations-5.1.0.Final.jar`
+* `<tomee-home>/lib/hibernate-core-5.4.10.Final.jar`
+* `<tomee-home>/lib/hibernate-entitymanager-5.4.10.Final.jar`
+* `<tomee-home>/lib/hibernate-validator-5.1.3.Final.jar`
+* `<tomee-home>/lib/jboss-logging-3.3.2.Final`
+* `<tomee-home>/lib/jandex-1.1.0.Final.jar`
+* `<tomee-home>/lib/javassist-3.18.1-GA.jar`
+* `<tomee-home>/lib/byte-buddy-1.10.2.jar`
+* `<tomee-home>/lib/classmate-1.0.0.jar`
+
 Remove (optional):
 
 * `<tomee-home>/lib/asm-3.2.jar`
diff --git a/examples/jpa-hibernate-arquillian/README.adoc b/examples/jpa-hibernate-arquillian/README.adoc
new file mode 100644
index 0000000..31343df
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/README.adoc
@@ -0,0 +1,323 @@
+= JPA Hibernate Arquillian
+:index-group: JPA
+:jbake-type: page
+:jbake-status: published
+
+This example shows the persist, remove and creation a query in JPA Hibernate 5 using arquillian for the test.
+
+The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database.
+
+To exemplify the use of JPA, we will persist an Object (Movie) in the database.
+
+Links to the documentation have been added in key parts of the example for the case of doubts and as a way to encourage their reading for details.
+
+== Movie
+
+Here we have a class with some details. See the annotation 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/Entity.html[@Entity] 
+above the declaration, with it we are saying that this class is an entity (a table in the database). We still have two more annotations above the attribute id, one of them is 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/Id.html[@Id] 
+annotation, it indicates that this attribute is the identifier of the entity and the other annotation 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/GeneratedValue.html[@GeneratedValue] 
+indicates that the unique identifier value generation of the entity will be managed by the persistence provider.
+
+[source,java]
+----
+package org.superbiz.injection.h3jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity
+public class Movie {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private long id;
+
+    private String director;
+    private String title;
+    private int year;
+
+    public Movie() {
+    }
+
+    public Movie(String director, String title, int year) {
+        this.director = director;
+        this.title = title;
+        this.year = year;
+    }
+
+    public String getDirector() {
+        return director;
+    }
+
+    public void setDirector(String director) {
+        this.director = director;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public void setYear(int year) {
+        this.year = year;
+    }
+
+}
+----
+
+== Movies
+
+Now we have two important things: 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/PersistenceContext.html[@PersistenceContext] 
+annotation and the 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/EntityManager.html[EntityManager] 
+declaration.
+The 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/EntityManager.html[EntityManager] 
+is the interface with the core methods of JPA like persist, remove, merge, find and others...
+We annotate the 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/EntityManager.html[EntityManager] 
+with 
+link:https://tomee.apache.org/tomee-8.0/javadoc/javax/persistence/PersistenceContext.html[@PersistenceContext], a persistence context is an entity management where  every persistence context associated with a persistence unit, we will create a persistence.xml soon for this.
+
+[source,java]
+----
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.Query;
+import javax.persistence.criteria.*;
+import javax.persistence.metamodel.EntityType;
+import java.util.List;
+
+@Stateful
+public class Movies {
+
+    @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
+    private EntityManager entityManager;
+
+    public void addMovie(Movie movie) throws Exception {
+        entityManager.persist(movie);
+    }
+
+    public void deleteMovie(Movie movie) throws Exception {
+        entityManager.remove(movie);
+    }
+
+    public List<Movie> getMovies() throws Exception {
+        Query query = entityManager.createQuery("SELECT m from Movie as m");
+        return query.getResultList();
+    }
+
+    public int count(String field, String searchTerm) {
+        CriteriaBuilder qb = entityManager.getCriteriaBuilder();
+        CriteriaQuery<Long> cq = qb.createQuery(Long.class);
+        Root<Movie> root = cq.from(Movie.class);
+        EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
+        cq.select(qb.count(root));
+        if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
+            Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
+            Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
+            cq.where(condition);
+        }
+        return entityManager.createQuery(cq).getSingleResult().intValue();
+    }
+
+}
+----
+
+== persistence.xml
+
+Here we define which database will persist our movies, and we perform other configurations such as: define a persistence-unit with the name movie-unit, followed by the definition of the JPA provider/implementation (in this case Hibernate 5) and we set some properties for hibernate 5:
+
+----
+ <persistence 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"
+             version="2.0">
+    <persistence-unit name="movie-unit">
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+        <jta-data-source>movieDatabase</jta-data-source>
+        <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
+        <class>org.superbiz.injection.h3jpa.Movie</class>
+        <properties>
+            <property name="hibernate.hbm2ddl.auto" value="update"/>
+            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+            <property name="hibernate.show_sql" value="true"/>
+
+            <!--
+            JPA and CDI are linked, enabling JPA to use CDI for its
+            components but CDI can use JPA too. To solve issues with
+            hibernate you need to this property either as system property
+            or persistence unit
+            -->
+            <property name="tomee.jpa.factory.lazy" value="true"/>
+        </properties>
+    </persistence-unit>
+</persistence>
+----
+
+
+== arquillian.xml
+This file provides the configuration the server will have for running the tests.
+The property `additionalLibs` provide to the server the jar files required for Hibernate 5 as explained in the http://tomee.apache.org/latest/docs/tomee-and-hibernate.html[TomEE and Hibernate] documentation.
+
+
+----
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<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="tomee" default="true">
+        <configuration>
+            <property name="httpPort">-1</property>
+            <property name="ajpPort">-1</property>
+            <property name="stopPort">-1</property>
+            <property name="dir">target/tomee-remote</property>
+            <property name="appWorkingDir">target/arquillian-remote-working-dir</property>
+            <property name="cleanOnStartUp">true</property>
+            <property name="additionalLibs">
+                <!-- add hibernate 5 need it jars to the server-->
+                mvn:org.hibernate:hibernate-entitymanager:5.4.10.Final
+                mvn:org.hibernate:hibernate-core:5.4.10.Final
+                mvn:org.hibernate.common:hibernate-commons-annotations:5.1.0.Final
+                mvn:antlr:antlr:2.7.7
+                mvn:org.jboss:jandex:1.1.0.Final
+                mvn:org.jboss.logging:jboss-logging:3.3.2.Final
+                mvn:dom4j:dom4j:1.6.1
+                mvn:org.javassist:javassist:3.18.1-GA
+                mvn:net.bytebuddy:byte-buddy:1.10.2
+                mvn:com.fasterxml:classmate:1.0.0
+            </property>
+
+        </configuration>
+    </container>
+</arquillian>
+----
+
+
+
+
+== MoviesArquillianTest
+
+Now we do a test with the following workflow:
+
+- Insert a movie.
+- Confirm that a movie was persisted by querying the number of movies from the data base.
+- Insert a second movie.
+- Delete the first movie
+- Confirm that the second movie is the only available in the data base.
+
+[source,java]
+----
+package org.superbiz.injection.h3jpa;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import javax.ejb.EJB;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class MoviesArquillianTest {
+
+    @Deployment
+    public static WebArchive createDeployment() {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClasses(Movie.class, Movies.class, MoviesArquillianTest.class)
+                .addAsResource(new ClassLoaderAsset("META-INF/persistence.xml"), "META-INF/persistence.xml");
+    }
+
+    @EJB
+    private Movies movies;
+
+    @Test
+    public void shouldBeAbleToAddAMovie() throws Exception {
+        assertNotNull("Verify that the ejb was injected", movies);
+
+        //Insert a movie
+        final Movie movie = new Movie();
+        movie.setDirector("Michael Bay");
+        movie.setTitle("Bad Boys");
+        movie.setYear(1995);
+        movies.addMovie(movie);
+
+        //Count movies
+        assertEquals(1, movies.count("title", "a"));
+
+        //Insert a movie
+        movies.addMovie(new Movie("David Dobkin", "Wedding Crashers", 2005));
+
+        //Get movies
+        assertEquals(2, movies.getMovies().size());
+
+        //Delete
+        movies.deleteMovie(movie);
+
+        //Get movies
+        assertEquals(2005, movies.getMovies().get(0).getYear());
+    }
+}
+----
+
+= Running
+
+To run the example via maven:
+
+Access the project folder:
+[source,java]
+----
+cd jpa-hibernate-arquillian
+----
+And execute:
+[source,java]
+----
+mvn clean install
+----
+
+Which will generate output similar to the following:
+
+[source,console]
+----
+...
+INFO [http-nio-56012-exec-3] org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized MyFaces Core has started, it took [2112] ms.
+INFO [http-nio-56012-exec-5] org.hibernate.jpa.internal.util.LogHelper.logPersistenceUnitInformation HHH000204: Processing PersistenceUnitInfo [name: movie-unit]
+INFO [http-nio-56012-exec-5] org.hibernate.Version.logVersion HHH000412: Hibernate Core {5.4.10.Final}
+INFO [http-nio-56012-exec-5] org.hibernate.annotations.common.reflection.java.JavaReflectionManager.<clinit> HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
+INFO [http-nio-56012-exec-5] org.hibernate.dialect.Dialect.<init> HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
+INFO [http-nio-56012-exec-5] org.hibernate.engine.transaction.jta.platform.internal.JtaPlatformInitiator.initiateService HHH000490: Using JtaPlatform implementation: [org.apache.openejb.hibernate.OpenEJBJtaPlatform2]
+Hibernate: create table Movie (id bigint not null, director varchar(255), title varchar(255), year integer not null, primary key (id))
+Hibernate: create sequence hibernate_sequence start with 1 increment by 1
+INFO [http-nio-56012-exec-5] org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createDelegate PersistenceUnit(name=movie-unit, provider=org.hibernate.jpa.HibernatePersistenceProvider) - provider time 4033ms
+Hibernate: call next value for hibernate_sequence
+Hibernate: insert into Movie (director, title, year, id) values (?, ?, ?, ?)
+Hibernate: select count(movie0_.id) as col_0_0_ from Movie movie0_ where movie0_.title like ?
+Hibernate: call next value for hibernate_sequence
+Hibernate: insert into Movie (director, title, year, id) values (?, ?, ?, ?)
+Hibernate: select movie0_.id as id1_0_, movie0_.director as director2_0_, movie0_.title as title3_0_, movie0_.year as year4_0_ from Movie movie0_
+Hibernate: delete from Movie where id=?
+Hibernate: select movie0_.id as id1_0_, movie0_.director as director2_0_, movie0_.title as title3_0_, movie0_.year as year4_0_ from Movie movie0_
+...
+INFO [main] org.apache.openejb.assembler.classic.Assembler.doResourceDestruction Closing DataSource: Default Unmanaged JDBC Database
+INFO [main] sun.reflect.DelegatingMethodAccessorImpl.invoke Destroying ProtocolHandler ["http-nio-56012"]
+Results :
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
+----
diff --git a/examples/jpa-hibernate-arquillian/pom.xml b/examples/jpa-hibernate-arquillian/pom.xml
new file mode 100644
index 0000000..f22edcc
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/pom.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<!-- $Rev: 636494 $ $Date: 2008-03-12 21:24:02 +0100 (Wed, 12 Mar 2008) $ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.superbiz</groupId>
+  <artifactId>jpa-hibernate-arquillian</artifactId>
+  <packaging>jar</packaging>
+  <version>8.0.7-SNAPSHOT</version>
+  <name>TomEE :: Examples :: JPA with Hibernate and arquillian</name>
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+     <tomee.version>8.0.7-SNAPSHOT</tomee.version>
+  </properties>
+  <build>
+    <defaultGoal>install</defaultGoal>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.5.1</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.tomitribe.transformer</groupId>
+        <artifactId>org.eclipse.transformer.maven</artifactId>
+        <version>0.1.1a</version>
+        <configuration>
+          <classifier>jakartaee9</classifier>
+        </configuration>
+        <executions>
+          <execution>
+            <goals>
+              <goal>run</goal>
+            </goals>
+            <phase>package</phase>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <id>apache-m2-snapshot</id>
+      <name>Apache Snapshot Repository</name>
+      <url>https://repository.apache.org/content/groups/snapshots</url>
+    </repository>
+    <repository>
+      <id>jboss-public-repository-group</id>
+      <name>JBoss Public Maven Repository Group</name>
+      <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
+      <layout>default</layout>
+      <releases>
+        <enabled>true</enabled>
+        <updatePolicy>always</updatePolicy>
+      </releases>
+      <snapshots>
+        <enabled>true</enabled>
+        <updatePolicy>always</updatePolicy>
+      </snapshots>
+    </repository>
+  </repositories>
+
+    <dependencyManagement>
+        <dependencies>
+            <!-- Override dependency resolver with test version. This must go *BEFORE*
+              the Arquillian BOM. -->
+            <dependency>
+                <groupId>org.jboss.shrinkwrap.resolver</groupId>
+                <artifactId>shrinkwrap-resolver-bom</artifactId>
+                <version>3.1.4</version>
+                <scope>import</scope>
+                <type>pom</type>
+            </dependency>
+            <!-- Now pull in our server-based unit testing framework -->
+            <dependency>
+                <groupId>org.jboss.arquillian</groupId>
+                <artifactId>arquillian-bom</artifactId>
+                <version>1.0.3.Final</version>
+                <scope>import</scope>
+                <type>pom</type>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.tomee</groupId>
+      <artifactId>javaee-api</artifactId>
+      <version>[8.0,)</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.12</version>
+      <scope>test</scope>
+    </dependency>
+
+
+      <dependency>
+          <groupId>org.jboss.arquillian.junit</groupId>
+          <artifactId>arquillian-junit-container</artifactId>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.jboss.shrinkwrap.resolver</groupId>
+          <artifactId>shrinkwrap-resolver-depchain</artifactId>
+          <type>pom</type>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.apache.tomee</groupId>
+          <artifactId>arquillian-tomee-remote</artifactId>
+          <version>${tomee.version}</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.apache.tomee</groupId>
+          <artifactId>apache-tomee</artifactId>
+          <version>${tomee.version}</version>
+          <type>zip</type>
+          <classifier>plus</classifier>
+          <scope>test</scope>
+      </dependency>
+  </dependencies>
+
+  <!--
+  This section allows you to configure where to publish libraries for sharing.
+  It is not required and may be deleted.  For more information see:
+  http://maven.apache.org/plugins/maven-deploy-plugin/
+  -->
+  <distributionManagement>
+    <repository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/repo/</url>
+    </repository>
+    <snapshotRepository>
+      <id>localhost</id>
+      <url>file://${basedir}/target/snapshot-repo/</url>
+    </snapshotRepository>
+  </distributionManagement>
+</project>
diff --git a/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movie.java b/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movie.java
new file mode 100644
index 0000000..e3c69fc
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movie.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.injection.h3jpa;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+@Entity
+public class Movie {
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.AUTO)
+    private long id;
+
+    private String director;
+    private String title;
+    private int year;
+
+    public Movie() {
+    }
+
+    public Movie(String director, String title, int year) {
+        this.director = director;
+        this.title = title;
+        this.year = year;
+    }
+
+    public String getDirector() {
+        return director;
+    }
+
+    public void setDirector(String director) {
+        this.director = director;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public int getYear() {
+        return year;
+    }
+
+    public void setYear(int year) {
+        this.year = year;
+    }
+
+}
diff --git a/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movies.java b/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movies.java
new file mode 100644
index 0000000..e8991fa
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/main/java/org/superbiz/injection/h3jpa/Movies.java
@@ -0,0 +1,61 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.injection.h3jpa;
+
+import javax.ejb.Stateful;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.Query;
+import javax.persistence.criteria.*;
+import javax.persistence.metamodel.EntityType;
+import java.util.List;
+
+@Stateful
+public class Movies {
+
+    @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.EXTENDED)
+    private EntityManager entityManager;
+
+    public void addMovie(Movie movie) throws Exception {
+        entityManager.persist(movie);
+    }
+
+    public void deleteMovie(Movie movie) throws Exception {
+        entityManager.remove(movie);
+    }
+
+    public List<Movie> getMovies() throws Exception {
+        Query query = entityManager.createQuery("SELECT m from Movie as m");
+        return query.getResultList();
+    }
+
+    public int count(String field, String searchTerm) {
+        CriteriaBuilder qb = entityManager.getCriteriaBuilder();
+        CriteriaQuery<Long> cq = qb.createQuery(Long.class);
+        Root<Movie> root = cq.from(Movie.class);
+        EntityType<Movie> type = entityManager.getMetamodel().entity(Movie.class);
+        cq.select(qb.count(root));
+        if (field != null && searchTerm != null && !"".equals(field.trim()) && !"".equals(searchTerm.trim())) {
+            Path<String> path = root.get(type.getDeclaredSingularAttribute(field.trim(), String.class));
+            Predicate condition = qb.like(path, "%" + searchTerm.trim() + "%");
+            cq.where(condition);
+        }
+        return entityManager.createQuery(cq).getSingleResult().intValue();
+    }
+
+}
diff --git a/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/beans.xml b/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/beans.xml
new file mode 100644
index 0000000..1d7c79f
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
+       bean-discovery-mode="all"
+       version="2.0">
+</beans>
\ No newline at end of file
diff --git a/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/persistence.xml b/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..372bf7b
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/main/resources/META-INF/persistence.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<persistence 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"
+             version="2.0">
+    <persistence-unit name="movie-unit">
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+        <jta-data-source>movieDatabase</jta-data-source>
+        <non-jta-data-source>movieDatabaseUnmanaged</non-jta-data-source>
+        <class>org.superbiz.injection.h3jpa.Movie</class>
+        <properties>
+            <property name="hibernate.hbm2ddl.auto" value="update"/>
+            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
+            <property name="hibernate.show_sql" value="true"/>
+
+            <!--
+            JPA and CDI are linked, enabling JPA to use CDI for its
+            components but CDI can use JPA too. To solve issues with
+            hibernate you need to this property either as system property
+            or persistence unit
+            -->
+            <property name="tomee.jpa.factory.lazy" value="true"/>
+        </properties>
+    </persistence-unit>
+</persistence>
diff --git a/examples/jpa-hibernate-arquillian/src/test/java/org/superbiz/injection/h3jpa/MoviesArquillianTest.java b/examples/jpa-hibernate-arquillian/src/test/java/org/superbiz/injection/h3jpa/MoviesArquillianTest.java
new file mode 100644
index 0000000..3c3fbff
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/test/java/org/superbiz/injection/h3jpa/MoviesArquillianTest.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.superbiz.injection.h3jpa;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJB;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(Arquillian.class)
+public class MoviesArquillianTest {
+
+    @Deployment
+    public static WebArchive createDeployment() {
+        return ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClasses(Movie.class, Movies.class, MoviesArquillianTest.class)
+                .addAsResource(new ClassLoaderAsset("META-INF/persistence.xml"), "META-INF/persistence.xml");
+    }
+
+    @EJB
+    private Movies movies;
+
+    @Test
+    public void shouldBeAbleToAddAMovie() throws Exception {
+
+        assertNotNull("Verify that the ejb was injected", movies);
+
+        //Insert a movie
+        final Movie movie = new Movie();
+        movie.setDirector("Michael Bay");
+        movie.setTitle("Bad Boys");
+        movie.setYear(1995);
+        movies.addMovie(movie);
+
+        //Count movies
+        assertEquals(1, movies.count("title", "a"));
+
+        //Insert a movie
+        movies.addMovie(new Movie("David Dobkin", "Wedding Crashers", 2005));
+
+        //Get movies
+        assertEquals(2, movies.getMovies().size());
+
+        //Delete
+        movies.deleteMovie(movie);
+
+        //Get movies
+        assertEquals(2005, movies.getMovies().get(0).getYear());
+    }
+
+}
\ No newline at end of file
diff --git a/examples/jpa-hibernate-arquillian/src/test/resources/arquillian.xml b/examples/jpa-hibernate-arquillian/src/test/resources/arquillian.xml
new file mode 100644
index 0000000..e55b693
--- /dev/null
+++ b/examples/jpa-hibernate-arquillian/src/test/resources/arquillian.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<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="tomee" default="true">
+        <configuration>
+            <property name="httpPort">-1</property>
+            <property name="ajpPort">-1</property>
+            <property name="stopPort">-1</property>
+            <property name="dir">target/tomee-remote</property>
+            <property name="appWorkingDir">target/arquillian-remote-working-dir</property>
+            <property name="cleanOnStartUp">true</property>
+            <property name="additionalLibs">
+                <!-- add hibernate 5 need it jars to the server-->
+                mvn:org.hibernate:hibernate-entitymanager:5.4.10.Final
+                mvn:org.hibernate:hibernate-core:5.4.10.Final
+                mvn:org.hibernate.common:hibernate-commons-annotations:5.1.0.Final
+                mvn:antlr:antlr:2.7.7
+                mvn:org.jboss:jandex:1.1.0.Final
+                mvn:org.jboss.logging:jboss-logging:3.3.2.Final
+                mvn:dom4j:dom4j:1.6.1
+                mvn:org.javassist:javassist:3.18.1-GA
+                mvn:net.bytebuddy:byte-buddy:1.10.2
+                mvn:com.fasterxml:classmate:1.0.0
+            </property>
+
+        </configuration>
+    </container>
+</arquillian>
diff --git a/examples/pom.xml b/examples/pom.xml
index de8267c..b4e4b93 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -93,6 +93,7 @@
     <module>jaxrs-json-provider-jettison</module>
     <module>jpa-eclipselink</module>
     <module>jpa-hibernate</module>
+    <module>jpa-hibernate-arquillian</module>
     <module>jpa-enumerated</module>
     <module>jsf-managedBean-and-ejb</module>
     <module>jsf-cdi-and-ejb</module>