10 Replies Latest reply on Jul 5, 2011 12:47 PM by lightguard

    How to inject Hibernate session in non JEE env?

    marcio.dantas

      Guys,


      I'm trying out Weld in Tomcat 6 (non JEE environment).


      My app uses Weld 1.0.0-CR2 and Hibernate 3.5.1-Final with annotations.


      The next thing I'ld like to do is using seam to inject session or entityManager instances on my beans. How this is done?? I examined the seam persistence module, but I failed to understand how to acomplish the task.


      thx,
      marcio

        • 1. Re: How to inject Hibernate session in non JEE env?
          marcio.dantas

          being more specific:


          do I have to create a class with a field producer? (seam-persistence doc)



          In Seam 2, both session factory and  extended session could be configured in components.xml.
          Is this possible in Seam 3?

          • 2. Re: How to inject Hibernate session in non JEE env?
            lightguard

            Yes, create the producer. Because of the use of non CDI annotations (@PersistenceUnit in particular) I don't think you could use seam-beans.xml to do this.

            • 3. Re: How to inject Hibernate session in non JEE env?
              marcio.dantas

              Ok, Jason.


              I was using hibernate.cfg.xml to configure persistence. Now I'll have to use Tomcat's context.xml declaring a persistence unit and reference it on the produce field, right?


              Like:



              @ExtensionManaged
              @Produces
              @PersistenceUnit(unitName = "myPersistenceUnit")
              @ConversationScoped
              EntityManagerFactory producerField;




              Another doubt: the documentation says: To use this you must have a Seam Managed Persistence Context installed with qualifier @Default.


              How this is done?


              thx

              • 4. Re: How to inject Hibernate session in non JEE env?
                lightguard

                Looks like you have that solved in your other post correct?


                @ConversationScoped -> @Default or left out all together

                • 5. Re: How to inject Hibernate session in non JEE env?
                  marcio.dantas

                  Not really.



                  Caused by: java.lang.RuntimeException: javax.persistence.PersistenceException: No Persistence provider for EntityManager named 
                       at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:126)
                       at org.jboss.seam.persistence.ManagedPersistenceContextBeanLifecycle.create(ManagedPersistenceContextBeanLifecycle.java:46)
                       at org.jboss.seam.solder.bean.ImmutableBean.create(ImmutableBean.java:87)
                       at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:121)
                       at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:99)
                       at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:124)
                       at org.jboss.weld.proxies.SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-teste$testeArchJSF$SeamManagedSessionFactoryProducer$entityManagerFactory$@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=)@org$jboss$seam$solder$core$ExtensionManaged()$_$$_WeldClientProxy.createQuery(SMPC-org$jboss$seam$persistence$ManagedPersistenceContextExtension-teste$testeArchJSF$SeamManagedSessionFactoryProducer$entityManagerFactory$@javax$enterprise$context$ConversationScoped()@javax$enterprise$inject$Produces()@javax$persistence$PersistenceUnit(name=,unitName=)@org$jboss$seam$solder$core$ExtensionManaged()$_$$_WeldClientProxy.java)



                  Does Tomcat really process persistence.xml file? Isn't it a JEE file?


                  I've tested my DataSource using the code below



                       try {
                            cxt = new InitialContext();
                            final DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc-hqsql" );
                            System.out.println(ds.toString());
                       } catch (final Exception e) {
                            throw new RuntimeException("Uh oh -- no context!");
                       }



                  and it's fine, but Seam still doesn't find the persistence unit. I'll post my files below.
                  Please take a look.


                  Class with producer method:


                  package teste.testeArchJSF;
                  
                  import javax.enterprise.context.ConversationScoped;
                  import javax.enterprise.inject.Produces;
                  import javax.persistence.EntityManagerFactory;
                  import javax.persistence.PersistenceUnit;
                  
                  import org.jboss.seam.solder.core.ExtensionManaged;
                  
                  public class SeamManagedSessionFactoryProducer {
                       @SuppressWarnings("unused")
                       @ExtensionManaged
                       @Produces
                       @PersistenceUnit
                       @ConversationScoped
                       private EntityManagerFactory entityManagerFactory;
                  }
                  



                  Class that injects entity manager:


                  package teste.testeArchJSF;
                  
                  import javax.annotation.PostConstruct;
                  import javax.inject.Inject;
                  import javax.inject.Named;
                  import javax.naming.InitialContext;
                  import javax.naming.NamingException;
                  import javax.persistence.EntityManager;
                  import javax.sql.DataSource;
                  import javax.validation.constraints.Digits;
                  import javax.validation.constraints.NotNull;
                  import javax.validation.constraints.Pattern;
                  
                  import org.hibernate.validator.constraints.Email;
                  import org.hibernate.validator.constraints.NotEmpty;
                  
                  @Named
                  public class HelloWorld
                  {
                     private final String text = "Hello World!";
                  
                     private String letters;
                  
                     private String numbers;
                  
                     private String email;
                  
                     @Inject
                     private EntityManager entityManager;
                  
                     public HelloWorld() {}
                  
                     @PostConstruct
                     public void initialize()
                     {
                          InitialContext cxt;
                       try {
                            cxt = new InitialContext();
                            final DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc-hqsql" );
                            System.out.println(ds.toString());
                       } catch (final Exception e) {
                            throw new RuntimeException("Uh oh -- no context!");
                       }
                  
                       System.out.println(this.getClass().getSimpleName() + " was constructed");
                     }
                  
                     public String getText()
                     {
                        return text;
                     }
                  
                     @NotNull
                     @NotEmpty
                     @Pattern(regexp = "[A-Za-z]*", message = "must contain only letters")
                     public String getLetters()
                     {
                          System.out.println(entityManager.createQuery("from Event").
                                    getResultList());
                        return letters;
                     }
                  
                     public void setLetters(String letters)
                     {
                        this.letters = letters;
                     }
                  
                     @NotNull
                     @NotEmpty
                     @Digits(fraction = 0, integer = 2)
                     public String getNumbers()
                     {
                        return numbers;
                     }
                  
                     public void setNumbers(String numbers)
                     {
                        this.numbers = numbers;
                     }
                  
                     @NotNull
                     @NotEmpty
                     @Email
                     public String getEmail()
                     {
                        return email;
                     }
                  
                     public void setEmail(String email)
                     {
                        this.email = email;
                     }
                  
                  }





                  persistence.xml:


                  <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="pu" transaction-type="RESOURCE_LOCAL">
                      <provider>org.hibernate.ejb.HibernatePersistence</provider>
                      <non-jta-data-source>java:/comp/env/jdbc-hqsql</non-jta-data-source>
                        <properties> 
                           <!-- Disable the second-level cache  -->
                           <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
                  
                          <!-- Echo all executed SQL to stdout -->
                          <property name="hibernate.show_sql">true</property>
                  
                          <!-- maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one). -->
                          <property name="hibernate.max_fetch_depth">0</property>
                  
                          <!-- enables use of JDBC2 batch updates by Hibernate. e.g. recommended values between 5 and 30. -->
                          <property name="hibernate.jdbc.batch_size">30</property> 
                          
                          <!-- auto-commit -->
                          <property name="hibernate.connection.autocommit">false</property>
                  
                          <!-- Drop and re-create the database schema on startup -->
                          <property name="hbm2ddl.auto">update</property>
                  
                          <!-- database dialect: http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html -->
                          <!-- <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property> -->
                  
                          <!-- sets responsible for tracking the current contextual session -->
                          <!-- <property name="hibernate.current_session_context_class">managed</property> -->
                           
                      </properties>
                    </persistence-unit>
                  </persistence>



                  web.xml:


                  <?xml version="1.0" encoding="UTF-8"?>
                  <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                      version="2.5">
                      <!-- JSF -->
                      <servlet>
                          <servlet-name>Faces Servlet</servlet-name>
                          <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                          <load-on-startup>1</load-on-startup>
                      </servlet>
                      <servlet-mapping>
                          <servlet-name>Faces Servlet</servlet-name>
                          <url-pattern>*.jsf</url-pattern>
                      </servlet-mapping>
                      <context-param>
                          <param-name>facelets.DEVELOPMENT</param-name>
                          <param-value>true</param-value>
                      </context-param>
                  
                      <!-- DAta source -->
                      <resource-ref>
                          <description>hqsql datasource example</description>
                          <res-ref-name>jdbc-hqsql</res-ref-name>
                          <res-type>javax.sql.DataSource</res-type>
                          <res-auth>Container</res-auth>
                      </resource-ref>
                  
                      <!-- CDI -->
                      <listener>
                          <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
                      </listener>
                  
                      <resource-env-ref>
                          <description>Object factory for the CDI Bean Manager</description>
                          <resource-env-ref-name>BeanManager</resource-env-ref-name>
                          <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
                      </resource-env-ref>
                  </web-app>



                  beans.xml:


                  <?xml version="1.0" encoding="UTF-8"?>
                  <!-- The contents of this file is permitted to be empty. The schema definition 
                      is provided for your convenience. -->
                  <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xsi:schemaLocation="
                        http://java.sun.com/xml/ns/javaee 
                        http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
                      <interceptors>
                          <class>org.jboss.seam.transaction.TransactionInterceptor</class>
                      </interceptors>
                  </beans>



                  seam-beans.xml:


                  <?xml version="1.0" encoding="UTF-8"?>
                  <beans xmlns="http://java.sun.com/xml/ns/javaee" 
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xmlns:s="urn:java:ee" xmlns:t="urn:java:org.jboss.seam.transaction"
                      xsi:schemaLocation="
                        http://java.sun.com/xml/ns/javaee
                        http://docs.jboss.org/cdi/beans_1_0.xsd">
                      <t:SeSynchronizations>
                          <s:modifies />
                      </t:SeSynchronizations>
                      <t:EntityTransaction>
                          <s:modifies />
                      </t:EntityTransaction>
                  </beans>


                  • 6. Re: How to inject Hibernate session in non JEE env?
                    florianhell

                    Take a look at the jetty-hibernate example bundled in the Seam Persistence Module. May this can fix ur problem.


                    Florian

                    • 7. Re: How to inject Hibernate session in non JEE env?
                      marcio.dantas

                      Thanks for the tip Florian. Really helped.


                      I was not able to inject the entityManger, cause the error above persisted (still think Tomcat doesn't support persistence.xml).


                      So, at least for now, I sticked with hibernate.cfg.xml and hibernate gets started by:


                      public class ManagedHibernateSessionProvider {
                          @RequestScoped
                          @Produces
                          @ExtensionManaged
                          public SessionFactory createSessionFactory() {
                              final Configuration config = new AnnotationConfiguration();
                              config.configure();
                              return config.buildSessionFactory();
                          }
                      }
                      



                      which is a class very similar to the one found at :



                      /seam-persistence/tests/base/src/main/java/org/jboss/seam/persistence/test/util/
                      ManagedHibernateSessionProvider.java

                      PS: Maybe I'll have to change the scope to application, but didn't test yet.



                      After this step, I had a problem with transactions. Seam wasn't using the configuration in beans.xml and seam-beans.xml. The problem was in my dependencies (version of artifact seam-xml-config and removal of weld-extensions), web.xml (seam forge resource listener needed) and seam-beans.xml (hibernate transaction instead of entity manager's).


                      It was a real pain but it ended well.
                      Thanks to all for the help!



                      seam-beans.xml:


                      <?xml version="1.0" encoding="UTF-8"?>
                      <beans xmlns="http://java.sun.com/xml/ns/javaee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                             xmlns:s="urn:java:ee"
                             xmlns:t="urn:java:org.jboss.seam.transaction"
                             xsi:schemaLocation="
                            http://java.sun.com/xml/ns/javaee
                            http://docs.jboss.org/cdi/beans_1_0.xsd">
                      
                          <t:SeSynchronizations>
                              <s:modifies/>
                          </t:SeSynchronizations>
                      
                          <t:HibernateTransaction>
                              <s:modifies/>
                          </t:HibernateTransaction>
                      </beans>



                      web.xml:


                      <?xml version="1.0" encoding="UTF-8"?>
                      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                          version="2.5">
                          <!-- JSF -->
                          <servlet>
                              <servlet-name>Faces Servlet</servlet-name>
                              <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                              <load-on-startup>1</load-on-startup>
                          </servlet>
                          <servlet-mapping>
                              <servlet-name>Faces Servlet</servlet-name>
                              <url-pattern>*.jsf</url-pattern>
                          </servlet-mapping>
                          <context-param>
                              <param-name>facelets.DEVELOPMENT</param-name>
                              <param-value>true</param-value>
                          </context-param>
                      
                          <!-- Seam solder -->
                          <listener>
                              <listener-class>org.jboss.seam.solder.resourceLoader.servlet.ResourceListener</listener-class>
                          </listener>
                          <!-- CDI -->
                          <listener>
                              <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
                          </listener>
                      
                          <resource-env-ref>
                              <description>Object factory for the CDI Bean Manager</description>
                              <resource-env-ref-name>BeanManager</resource-env-ref-name>
                              <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
                          </resource-env-ref>
                      </web-app>




                      pom.xml:




                      <?xml version="1.0" encoding="UTF-8"?>
                      <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>teste</groupId>
                         <artifactId>testeArchJSF</artifactId>
                         <packaging>war</packaging>
                         <name>testeArchJSF</name>
                         <version>1.0.0-SNAPSHOT</version>
                      
                         <properties>
                            <!--
                               Explicitly declaring the source encoding eliminates the following message:
                               [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
                            -->
                            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                            <!-- The version of Weld extensions in use -->
                            <weld.extensions.version>1.0.0-CR2</weld.extensions.version>
                         </properties>
                      
                          <repositories>
                              <!-- The JBoss Community public repository is a composite repository of several major repositories -->
                              <!-- see http://community.jboss.org/wiki/MavenGettingStarted-Users -->
                              <!-- At the time of writing, Arquillian and the JBoss Java EE specification POMs are only in the JBoss Community public 
                                  repository (not Maven central) -->
                              <repository>
                                  <id>jboss-public-repository</id>
                                  <name>JBoss Repository</name>
                                  <url>http://repository.jboss.org/nexus/content/groups/public</url>
                                  <!-- These optional flags are designed to speed up your builds by reducing remote server calls -->
                                  <releases>
                                      <updatePolicy>never</updatePolicy>
                                  </releases>
                                  <snapshots>
                                      <enabled>false</enabled>
                                  </snapshots>
                              </repository>
                              <!-- maven 2 central repository -->
                              <repository>
                                <id>Maven 2 Central</id>
                                <name>Maven 2 Central</name>
                                <url>https://repository.jboss.org/nexus/content/repositories/central/</url>
                                <releases>
                                    <updatePolicy>never</updatePolicy>
                                </releases>
                                <snapshots>
                                    <enabled>false</enabled>
                                </snapshots>
                              </repository>
                          </repositories>
                      
                          <pluginRepositories>
                              <pluginRepository>
                                  <id>jboss-release-repository</id>
                                  <name>JBoss Repository Releases</name>
                                  <url>https://repository.jboss.org/nexus/content/repositories/releases/</url>
                                  <!-- These optional flags are designed to speed up your builds by reducing remote server calls -->
                                  <releases>
                                      <enabled>true</enabled>
                                      <updatePolicy>never</updatePolicy>
                                  </releases>
                                  <snapshots>
                                      <enabled>true</enabled>
                                      <updatePolicy>never</updatePolicy>
                                  </snapshots>
                              </pluginRepository>
                          </pluginRepositories>
                      
                          <!-- build -->
                         <build>
                            <finalName>testeArchJSF</finalName>
                            <plugins>
                               <!-- Compiler plugin enforces Java 1.6 compatibility -->
                               <plugin>
                                  <groupId>org.apache.maven.plugins</groupId>
                                  <artifactId>maven-compiler-plugin</artifactId>
                                  <configuration>
                                     <source>1.6</source>
                                     <target>1.6</target>
                                  </configuration>
                               </plugin>
                      
                               <!-- Eclipse plugin - download source and JavaDoc jars automatically -->
                               <plugin>
                                  <groupId>org.apache.maven.plugins</groupId>
                                  <artifactId>maven-eclipse-plugin</artifactId>
                                  <configuration>
                                     <wtpversion>2.0</wtpversion>
                                     <downloadSources>true</downloadSources>
                                     <downloadJavadocs>true</downloadJavadocs>
                                  </configuration>
                               </plugin>
                      
                               <!-- Embedded Jetty (jetty:run) -->
                               <plugin>
                                  <groupId>org.mortbay.jetty</groupId>
                                  <artifactId>maven-jetty-plugin</artifactId>
                                  <configuration>
                                     <!-- Delete this block to have Jetty run default port (8080) -->
                                     <connectors>
                                        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                                           <port>9090</port>
                                        </connector>
                                     </connectors>
                                     <!-- force friendly name instead of artifact name + version -->
                                     <contextPath>${project.build.finalName}</contextPath>
                                     <!-- Where the BeanManager is constructed. This is where you'll declare datasources. -->
                                     <jettyEnvXml>${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
                                     <!-- This parameter will auto-deploy modified classes. -->
                                     <!-- You can save changes in a file or class and refresh your browser to view the changes. -->
                                     <scanIntervalSeconds>3</scanIntervalSeconds>
                                  </configuration>
                               </plugin>
                      
                               <!-- Embedded Tomcat (package tomcat:run) -->
                               <!-- Standalone Tomcat (package tomcat:deploy) -->
                               <plugin>
                                  <groupId>org.codehaus.mojo</groupId>
                                  <artifactId>tomcat-maven-plugin</artifactId>
                                  <configuration>
                                     <path>/${project.build.finalName}</path>
                                     <!-- Embedded port -->
                                     <port>9090</port>
                                     <!--
                                        The default authentication credentials for remote deployment are username "admin" with no password To
                                        override credentials, define a server in settings.xml and activate it using the <server> element
                                     -->
                                     <url>http://localhost:8080/manager</url>
                                  </configuration>
                               </plugin>
                            </plugins>
                         </build>
                      
                         <dependencyManagement>
                            <dependencies>
                               <!-- Import scope will provide versions for dependencies below. -->
                               <dependency>
                                  <groupId>org.jboss.weld</groupId>
                                  <artifactId>weld-extensions-bom</artifactId>
                                  <version>${weld.extensions.version}</version>
                                  <type>pom</type>
                                  <scope>import</scope>
                               </dependency>
                            </dependencies>
                         </dependencyManagement>
                      
                         <dependencies>
                      
                            <!-- Common to JEE and Servlet containers -->
                            <dependency>
                               <groupId>javax.enterprise</groupId>
                               <artifactId>cdi-api</artifactId>
                               <scope>provided</scope>
                            </dependency>
                      
                            <dependency>
                               <groupId>javax.annotation</groupId>
                               <artifactId>jsr250-api</artifactId>
                               <scope>provided</scope>
                            </dependency>
                      
                            <!-- JSF 2.0 API -->
                            <dependency>
                               <groupId>javax.faces</groupId>
                               <artifactId>jsf-api</artifactId>
                            </dependency>
                      
                            <!-- Optional, but pretty useful. -->
                          <dependency>
                              <groupId>javax.servlet</groupId>
                              <artifactId>jstl</artifactId>
                          </dependency>
                      
                          <!-- Needed for running tests (you may also use TestNG) -->
                          <dependency>
                              <groupId>junit</groupId>
                              <artifactId>junit</artifactId>
                              <version>4.8.1</version>
                              <scope>test</scope>
                          </dependency>
                      
                            <!-- Jetty/Tomcat-specific scopes and artifacts -->
                      
                            <!-- JSF 2.0 -->
                            <dependency>
                               <groupId>javax.faces</groupId>
                               <artifactId>jsf-impl</artifactId>
                               <scope>runtime</scope>
                            </dependency>
                      
                            <dependency>
                               <groupId>org.jboss.weld.servlet</groupId>
                               <artifactId>weld-servlet</artifactId>
                               <scope>runtime</scope>
                               <version>1.1.1.Final</version>
                            </dependency>
                      
                            <dependency>
                               <groupId>org.glassfish.web</groupId>
                               <artifactId>el-impl</artifactId>
                               <scope>runtime</scope>
                               <exclusions>
                                  <exclusion>
                                     <groupId>javax.el</groupId>
                                     <artifactId>el-api</artifactId>
                                  </exclusion>
                               </exclusions>
                            </dependency>
                            <!-- end Jetty/Tomcat-specific scopes and artifacts -->
                      
                            <!-- Bean Validation API (JSR 303) -->
                            <dependency>
                               <groupId>javax.validation</groupId>
                               <artifactId>validation-api</artifactId>
                            </dependency>
                      
                            <!-- Bean Validation Implementation -->
                            <!-- Provides portable constraints such as @NotEmpty, @Email and @Url -->
                            <dependency>
                               <groupId>org.hibernate</groupId>
                               <artifactId>hibernate-validator</artifactId>
                               <version>4.0.0.GA</version>
                            </dependency>
                      
                            <!-- Database Driver -->
                           <dependency>
                               <groupId>hsqldb</groupId>
                               <artifactId>hsqldb</artifactId>
                               <version>1.8.0.1</version>
                               <type>jar</type>
                               <scope>runtime</scope>
                           </dependency>
                      
                            <!-- hibernate -->
                           <dependency>
                              <groupId>org.hibernate</groupId>
                              <artifactId>hibernate-core</artifactId>
                              <version>3.5.1-Final</version>
                              <scope>compile</scope>
                           </dependency>
                      
                           <dependency>
                               <groupId>org.hibernate</groupId>
                               <artifactId>hibernate-annotations</artifactId>
                               <version>3.5.1-Final</version>
                               <type>jar</type>
                               <scope>compile</scope>
                           </dependency>
                      
                           <dependency>
                               <groupId>log4j</groupId>
                               <artifactId>log4j</artifactId>
                               <version>1.2.14</version>
                               <type>jar</type>
                               <scope>compile</scope>
                           </dependency>
                      
                           <dependency>
                              <groupId>javassist</groupId>
                              <artifactId>javassist</artifactId>
                              <version>3.12.0.GA</version>
                              <type>jar</type>
                              <scope>runtime</scope>
                           </dependency>
                      
                           <dependency>
                               <groupId>org.hibernate</groupId>
                               <artifactId>hibernate-c3p0</artifactId>
                               <version>3.5.1-Final</version>
                               <type>jar</type>
                               <scope>runtime</scope>
                           </dependency>
                      
                          <!-- Seam Persistence -->
                           <dependency>
                               <groupId>org.jboss.seam.persistence</groupId>
                               <artifactId>seam-persistence</artifactId>
                               <version>3.0.0.Final</version>
                               <scope>compile</scope>
                           </dependency>
                      
                          <dependency>
                              <groupId>org.jboss.logmanager</groupId>
                              <artifactId>jboss-logmanager</artifactId>
                              <version>1.2.0.CR9</version>
                          </dependency>
                      
                           <dependency>
                              <groupId>org.jboss.seam.config</groupId>
                              <artifactId>seam-config-xml</artifactId>
                              <version>3.0.0.Final</version>
                               <exclusions>
                                 <exclusion>
                                   <groupId>org.jboss.weld</groupId>
                                   <artifactId>weld-extensions</artifactId>
                                 </exclusion>
                               </exclusions>
                           </dependency>
                         </dependencies>
                      </project>
                      

                      • 8. Re: How to inject Hibernate session in non JEE env?
                        lightguard

                        No server supports persistence.xml, that's JPA's responsibility. Because you don't have a JPA implementation on the classpath (you'd need the hibernate entity manager artifact for that) there isn't anything in your application that supports reading and bootstrapping JPA. That's why it hasn't been working for you.


                        If you'd like an environment that runs all of this stuff out of the box, use an app server like JBoss, Glassfish, Geronimo, Resin, etc. If you haven't taken a look at JBoss AS7, you should at least take the time to see it. It starts up faster than tomcat :)

                        • 9. Re: How to inject Hibernate session in non JEE env?
                          marcio.dantas

                          so it's the entity manager artifact that bootstraps JPA.. very nice. I'll do it here.


                          I'm struggling to use tomcat because after a little research I found out that Tomcat hosting services are much cheaper. Does someone have any sugestion on that?


                          thx again,
                          cheers

                          • 10. Re: How to inject Hibernate session in non JEE env?
                            lightguard

                            Take a look at OpenShift. Flex account now uses AS6, and the Express version will be running AS7 once it's updated.