9 Replies Latest reply on Jun 4, 2013 9:18 AM by bmajsak

    Hibernate and CDI with tomcat-embedded

    yasharbi

      The example in http://arquillian.org/guides/testing_java_persistence/  is very straight forward for setting up the arquillian for Glassfish or Jboss , can anyone update this example to use Embedded tomcat or TomEE.

      Now it is more than a week that i am struggling  with setting CDI , hibernate and arquillian on tomcat-embedded ( or TomEE as an alternative) without any hope.

        • 1. Re: Hibernate and CDI with tomcat-embedded
          bmajsak

          As pointed out in another thread, tomcat embedded is not the best container for cdi and jpa, as you will need to wire it up by hand. Any luck with TomEE?

          • 2. Re: Hibernate and CDI with tomcat-embedded
            yasharbi

            I am able to run  TomEE and arquillian with hibernate and CDI on a sample project , but when I am trying to integrate it with my main project I am getting tha following error when I am running the test

             

                 Unable to build EntityManagerFactory

                Caused by: java.lang.ClassCastException: org.apache.openejb.hibernate.OpenEJBJtaPlatform cannot be cast to org.hibernate.service.jta.platform.spi.JtaPlatform

            • 3. Re: Hibernate and CDI with tomcat-embedded
              yasharbi

              My comppany persist to setting Arquillian with Tomcat-embedded 7, since we running that in the customers sites. So I have to throw a way TomEE and start with tomcat-embedded 7.

               

              I started to setting Arquillian with CDI , hibernate and tomcat-embedded 7. I could find a few example for CDI and tomcat-embedded 7 and it is working fine with my Arquillian tests, but I couldn't find any resources or example for setting Arquillian with hibernate and tomcat-embedded. (samples for setting data source , persistence.xml and shrinkWrap, listeners for running hibernate )

              I will appriciate anything in this regard ( example , URL , blog, source code). The only thing which I could find for tomcat and Arquillian is this URL https://github.com/arquillian/arquillian-container-tomcat/

              but there is nothing related to JPA (hibernate) settings in these examples

              • 4. Re: Hibernate and CDI with tomcat-embedded
                bmajsak

                I'm not really convinced if that's a good idea. Tomcat is bare bone and you will need to configure all your application stack by hand. 

                 

                At this moment we don't provide such setup in the example and we truly believe that for this very need TomEE is the right approach, as it gives you pre-configured, reliable and well tested Java EE environment based on vanilla Tomcat. Why would like to do the same job on your own?

                 

                The reason you were getting class cast exception posted before is because TomEE is shipped with OpenJPA as provider, however you can use hibernate if you like. Please have a look here http://tomee.apache.org/tomee-and-hibernate.html

                 

                What is your production environment btw?

                • 5. Re: Hibernate and CDI with tomcat-embedded
                  yasharbi

                  We are running  Weld-CDI ( converting right now from the previuosly written seam project)  , hibernate, JSF and MySQL on vanilla tomcat in the production envirement.

                  • 6. Re: Hibernate and CDI with tomcat-embedded
                    bmajsak

                    Ok, so you have done the work of configuring Tomcat for your own needs. I think you can re-apply the same process on embedded version through ShrinkWrap archives.

                    • 7. Re: Hibernate and CDI with tomcat-embedded
                      wangliyu

                      Don't try any embeded container, if you have CDI jar (included beans.xml), with embeded container, Weld will scan and try to load the same bean twice (because one is in the runtime classpath, and you put another one in the generated test war file), other hand the tomcat managed/remote container is better.

                      I'm switching the test from JBoss6 Remote to Tomcat7 managed Container, most part are good, onlything annoying me is Arquillian is not support Conversation Context.

                       

                      My code are OK to run with CDI 2.0 (in 2.0, the Conversation Scope is now activated with Servlet, no longer with JSF lifecycle). I think Arquillian team should do some work to catch up, also for the JBoss6 container, I have no idea if that part is dead or not. from what I have seen on github/G+, the team now is more like talking rather than doing (especially Dan?). This gives me some impression that the arquillian is just pet project?

                      • 8. Re: Hibernate and CDI with tomcat-embedded
                        yasharbi

                        I managed to setup arquillian with Hibernate, CDI and H2  database on embedded-tomcat 7

                         

                        https://github.com/Yasharbi/Arquillian-TomcatEmbedded-Hibernate-CDI-H2

                        • 9. Re: Hibernate and CDI with tomcat-embedded
                          bmajsak

                          Thanks a lot for contributing back to the community!