3 Replies Latest reply on Jun 12, 2007 4:24 AM by Tony Tony

    TestNG with hibernate

    Tony Tony Newbie

      Hi All,

      I would like to ask how to create session in hibernate session using testNG.
      One of example using this code below:

      EntityManagerFactory emf =
       Persistence.createEntityManagerFactory("helloworld");
       EntityManager em = emf.createEntityManager();


      Is it code usable for hibernate session? if not, how do I create session in test file?...

      here are my components.xml:

      ?xml version="1.0" encoding="UTF-8"?>
      <components xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://jboss.com/products/seam/security"
       xsi:schemaLocation="http://jboss.com/products/seam/core
       http://jboss.com/products/seam/core-1.1.xsd
       http://jboss.com/products/seam/components
       http://jboss.com/products/seam/components-1.1.xsd
       http://jboss.com/products/seam/security
       http://jboss.com/products/seam/security-1.1.xsd">
      
       <core:init debug="true" />
      
       <!-- <core:manager conversation-timeout="120000" /> -->
       <core:manager conversation-timeout="60000"
       concurrent-request-timeout="500"
       conversation-id-parameter="cid"
       conversation-is-long-running-parameter="clr" />
       <security:identity
       authenticate-method="#{authenticator.authenticate}" />
      
       <event type="org.jboss.seam.notLoggedIn">
       <action expression="#{redirect.captureCurrentView}" />
       </event>
      
       <event type="org.jboss.seam.postAuthenticate">
       <action expression="#{redirect.returnToCapturedView}" />
       </event>
       <!-- Bootstrap Hibernate -->
       <core:hibernate-session-factory />
       <core:managed-hibernate-session name="mySession" auto-create="true" />
      
      </components>
      
      


        • 2. Re: TestNG with hibernate
          Christian Bauer Master

          Session session = (Session)em.getDelegate();

          • 3. Re: TestNG with hibernate
            Tony Tony Newbie

            Hi Chris,

            Thx for the reply. I tried it but i gives me error. here are my simple code:

             EntityManagerFactory emf = Persistence.createEntityManagerFactory("mySession");
             EntityManager em = emf.createEntityManager();
             ManagedHibernateSession session = (ManagedHibernateSession) em.getDelegate();
            


            and here are the error:

            javax.persistence.PersistenceException: No Persistence provider for EntityManager named mySession
             at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
             at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
             at com.medansoft.controller.GeneralJournalActionTest.createGeneralJournalTest(GeneralJournalActionTest.java:19)
            ... Removed 21 stack frames
            
            ===============================================
             GeneralJournalAction
             Tests run: 1, Failures: 1, Skips: 0
            ===============================================
            
            
            ===============================================
            Accounting System Test Suite
            Total tests run: 1, Failures: 1, Skips: 0
            ===============================================
            


            As I named my hibernate session -- mySession in component.xml...
            Any help will be appreciated...

            Thanks