1 Reply Latest reply on May 31, 2008 2:03 AM by Matt Davis

    Problem with multiple datasources and TestNG

    Matt Davis Newbie

      Ok, I'm trying to get TestNG to pull data from a secondary database with which it will construct test objects.


      I'm running into problems with 2 datasources.


      I'm using a project that I generated using the New Seam Project feature of Jboss Tools. So there are 4 projects in my eclipse environment, one of them is called projname-test.


      The problem occurs when I add the line


       List objectsFound = q.getResultList();
      



      It is in the test class. It is listed below. The error goes away if I comment this one line out.


      Now, this is not where the error is actually occuring. The error occurs in my Stateless session bean that tries to use the other datasource. The error only occurs if I perform the query above in my test code prior to the session bean's call to EntityManager's persist.


      From MyEntityBean below:


      em.persist(myEntity);
      



      It's like it is opening up a transaction in my test code and not closing it, or something, and it screws up the next request to the other datasource.


      Note that I'm using a non-jta-datasource... This is because it didn't work to have it be a jta-datsource, because the call is coming from outside the container (or something like that).  Since it's not a session bean making the call... that's the conclusion I came to on my own earlier when I was  fixing another problem.


      The test code uses the projname-test-ds.xml instead of the projname-ds.xml  I made them identical... but I'm not sure if the container-managed beans use their own ds.xml file, or if the use the test one. 


      Any insight would be greatly appreciated.



      The full error that I get is this (code is below):


      ERROR [org.hibernate.util.JDBCExceptionReporter] Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >))
      ERROR [org.jboss.aspects.tx.TxPolicy] javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      FAILED: testAnomalyPersist
      java.lang.AssertionError: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.jboss.seam.mock.BaseSeamTest$Request.onException(BaseSeamTest.java:488)
          at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:537)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
          at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
          at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
          at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
          at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
          at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
          at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:524)
          at org.domain.projName.test.AnomalyTest.testAnomalyPersist(AnomalyTest.java:84)
      Caused by: javax.el.ELException: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:333)
          at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
          at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
          at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
          at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
          at org.jboss.seam.mock.BaseSeamTest$Request.invokeMethod(BaseSeamTest.java:496)
          at org.domain.projName.test.AnomalyTest$1.invokeApplication(AnomalyTest.java:67)
          at org.jboss.seam.mock.BaseSeamTest$Request.invokeApplicationPhase(BaseSeamTest.java:660)
          at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:609)
          at org.jboss.seam.mock.BaseSeamTest$Request.access$300(BaseSeamTest.java:184)
          at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:530)
          40 more
      Caused by: javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:91)
          at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
          at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:64)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:166)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:249)
          at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214)
          at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:86)
          at $Proxy73.persistAnomaly(Unknown Source)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
          at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
          at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
          at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
          at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
          at org.javassist.tmp.java.lang.Object_$$_javassist_1.persistAnomaly(Object_$$_javassist_1.java)
          at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
           50 more
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
          at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:219)
          at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:177)
          at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:135)
          at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.persist(FullTextEntityManagerImpl.java:82)
          at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:135)
          at org.domain.projName.session.AnomalyBean.persistAnomaly(AnomalyBean.java:34)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:121)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:110)
          at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
          at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
          at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:26)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:27)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
          at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
          at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
          at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
           84 more
      Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
          at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
          at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
          at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
          at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:123)
          at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
          at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
          at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
          at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
          at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
          at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
          at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
          at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
          at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
          at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
           122 more
      Caused by: org.jboss.util.NestedSQLException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >); - nested throwable: (org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >))
          at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)
          at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:47)
          at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
           134 more
      Caused by: org.jboss.resource.JBossResourceException: Could not enlist in transaction on entering meta-aware object!; - nested throwable: (javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >)
          at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:379)
          at org.jboss.resource.connectionmanager.BaseConnectionManager2.reconnectManagedConnection(BaseConnectionManager2.java:516)
          at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:397)
          at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:838)
          at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
           136 more
      Caused by: javax.transaction.SystemException: java.lang.Throwable: Unabled to enlist resource, see the previous warnings. tx=TransactionImple < ac, BasicAction: a010189:9670:4840563e:66 status: ActionStatus.ABORT_ONLY >
          at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener$TransactionSynchronization.checkEnlisted(TxConnectionManager.java:796)
          at org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener.enlist(TxConnectionManager.java:629)
          at org.jboss.resource.connectionmanager.TxConnectionManager.managedConnectionReconnected(TxConnectionManager.java:373)
           140 more
       Removed 38 stack frames
      
      ===============================================
          org.domain.projName.test.AnomalyTest
          Tests run: 1, Failures: 1, Skips: 0
      ===============================================
      
      
      ===============================================
      projName-test
      Total tests run: 1, Failures: 1, Skips: 0
      ===============================================
      
      



      persistence.xml


        <?xml version="1.0" encoding="UTF-8" ?> 
           <!--  Persistence deployment descriptor for dev profile  -->     
      <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_1_0.xsd" version="1.0">
      <persistence-unit name="DB1">
           <provider>org.hibernate.ejb.HibernatePersistence</provider> 
           <jta-data-source>java:/DB1Datasource</jta-data-source> 
           <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
                <property name="hibernate.hbm2ddl.auto" value="update" /> 
                <property name="hibernate.show_sql" value="true" /> 
                <property name="hibernate.format_sql" value="true" /> 
                <property name="jboss.entity.manager.factory.jndi.name" value="java:/DB1EntityManagerFactory" /> 
           </properties>
      </persistence-unit>
      <persistence-unit name="DB2">
           <provider>org.hibernate.ejb.HibernatePersistence</provider> 
           <non-jta-data-source>java:/DB2Datasource</non-jta-data-source> 
           <properties>
                <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
                <property name="hibernate.hbm2ddl.auto" value="update" /> 
                <property name="hibernate.show_sql" value="true" /> 
                <property name="hibernate.format_sql" value="true" /> 
                <property name="jboss.entity.manager.factory.jndi.name" value="java:/DB2EntityManagerFactory" /> 
                </properties>
           </persistence-unit>
      </persistence>
      
      



      projname-DS.xml


        <?xml version="1.0" encoding="UTF-8" ?> 
        <!DOCTYPE datasources (View Source for full doctype)> 
        <datasources>
           <local-tx-datasource>
           <jndi-name>DB1Datasource</jndi-name> 
           <connection-url>jdbc:postgresql://localhost:5432</connection-url> 
           <driver-class>org.postgresql.Driver</driver-class> 
           <user-name>DB1</user-name> 
           <password /> 
        </local-tx-datasource>
      
        <local-tx-datasource>
           <jndi-name>DB2Datasource</jndi-name> 
           <connection-url>jdbc:postgresql:DB2</connection-url> 
           <driver-class>org.postgresql.Driver</driver-class> 
           <user-name>DB2</user-name> 
           <password /> 
        </local-tx-datasource>
      </datasources>
      



      projname-test-ds.xml


      <?xml version="1.0" encoding="UTF-8"?>
      
      <!DOCTYPE datasources
          SYSTEM "bin/META-INF/jboss-ds_1_5.dtd">
          
      <datasources>
         
         <local-tx-datasource>
            <jndi-name>DB1Datasource</jndi-name>
      <connection-url>jdbc:postgresql://localhost:5432</connection-url>
            <driver-class>org.postgresql.Driver</driver-class>
            <user-name>DB1</user-name>
            <password></password>
         </local-tx-datasource>
      
         
         <local-tx-datasource>
            <jndi-name>DB2Datasource</jndi-name>
            <connection-url>jdbc:postgresql:DB2</connection-url>
            <driver-class>org.postgresql.Driver</driver-class>
            <user-name>DB2</user-name>
            <password></password>
          </local-tx-datasource>
          
      </datasources>
      
      
      



      Here is my test code:


      import java.util.Date;
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      import javax.persistence.Query;
      
      import org.testng.annotations.Test;
      import org.domain.mypackage.entity.MyEntity;
      import org.domain.mypackage.entity.MyEntitytest;
      import org.jboss.seam.mock.SeamTest;
      
      
      public class MyEntityTest extends SeamTest{
      
          
         
          private int m_numberOfTimes;
          public MyEntityTest(int numberOfTimes){
              m_numberOfTimes = numberOfTimes;
          }
          
          
          
          @Test
          public void testMyEntityPersist() throws Exception {
              final EntityManagerFactory emf = Persistence.createEntityManagerFactory("TestData");
              for(int i = 0; i < m_numberOfTimes; i ++){
                  new FacesRequest() {
                  @Override
                  protected void updateModelValues() throws Exception {
      
                      EntityManager em = emf.createEntityManager();
                      MyEntitytest myEntityTest = new MyEntitytest();
                      String hqlString = "from MyEntitytest";
                      Query q = em.createQuery(hqlString);
      
                  
                      List objectsFound = q.getResultList();
                      em.close();
                      
                      System.out.println("Found " + objectsFound.size() + "objects");
                      
                      
                      //set form input to model attributes
                      setValue("#{myEntity.port}", 23);
                      
                      setValue("#{myEntity.iVersion.number}", 1);
                      setValue("#{myEntity.iVersion.updatedon}", new Date(100000));
                      setValue("#{myEntity.iVersion.username}", "iVersion username");
                      setValue("#{myEntity.iVersion.status}", "iVersion status");
                      setValue("#{myEntity.iVersion.comment}", "iVersion comment");
                  }
                  @Override
                  protected void invokeApplication() {
                      //call action methods here
                      invokeMethod("#{MyEntityBean.persistMyEntity}");
                  }
                  @Override
                  protected void renderResponse() {
                      //check model attributes if needed
                      assert getValue("#{myEntity.port}").getClass() == Long.class;
                      assert getValue("#{myEntity.port}").equals(new Long(23));
      
                      assert getValue("#{myEntity.iVersion.number}").getClass() == Long.class;
                      assert getValue("#{myEntity.iVersion.number}").equals(new Long(1));
                      assert getValue("#{myEntity.iVersion.updatedon}").equals(new Date(100000));
                      assert getValue("#{myEntity.iVersion.username}").equals("iVersion username");
                      assert getValue("#{myEntity.iVersion.status}").equals("iVersion status");
                      assert getValue("#{myEntity.iVersion.comment}").equals("iVersion comment");
                      
                  }
              }.run();
              }
              
              
          }
      }
      



      and:


      import org.testng.annotations.Factory;
      
      public class MyEntityTestFactory {
          @Factory
          public Object[] createInstances(){
              
              int numTimes = 1;
              Object[] result = new Object[numTimes];
              for(int i = 0; i < numTimes; i++){
                  result[i] = new MyEntityTest(numTimes);
              }
              return result;
          }
      }
      
      
      



      MyEntityTest.xml


      <!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
      
      <suite name="MyEntity Tests" verbose="2" parallel="false">
         <test name="MyEntity Test">
           <classes>
             <class name="org.domain.mypackage.test.MyEntityTestFactory"/>       
           </classes>
         </test>    
      </suite>
      



      My entity bean:


      
      import java.io.Serializable;
      
      import javax.persistence.AttributeOverrides;
      import javax.persistence.Column;
      import javax.persistence.Embedded;
      import javax.persistence.Entity;
      
      import javax.persistence.EnumType;
      import javax.persistence.Enumerated;
      import javax.persistence.GenerationType;
      import javax.persistence.Id;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Version;
      import org.jboss.seam.annotations.Name;
      
      @Entity
      @Name("myEntity")
      public class MyEntity implements Serializable {
      
          //seam-gen attributes (you should probably edit these)
          private long id;
          private long port;
          private IVersion iVersion = new IVersion();
      
          //add additional entity attributes
      
          //seam-gen attribute getters/setters with annotations (you probably should edit)
      
          @Id
          @GeneratedValue(strategy = GenerationType.AUTO)
          @Column(name = "id", unique = true, nullable = false)
          public long getId() {
              return id;
          }
      
          public void setId(long id) {
              this.id = id;
          }
      
          @Version
          @Column(name = "optlock")
          public int getVersion() {
              return version;
          }
      
          private void setVersion(int version) {
              this.version = version;
          }
      
          @Column(name = "port", nullable = false)
          public long getPort() {
              return port;
          }
      
          public void setPort(long port) {
              this.port = port;
          }
          @Embedded
          public IVersion getIVersion() {
              return this.iVersion;
          }
      
          public void setIVersion(IVersion iVersion) {
              this.iVersion = iVersion;
          }
      }
      
      



      Statless session bean


      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceContext;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.faces.FacesMessages;
      import org.domain.mypackage.entity.MyEntity ;
      
      @Stateless
      @Name("MyEntityBean")
      public class MyEntityBean implements MyEntityInterface {
      
          @Logger private Log log;
          
          @In FacesMessages facesMessages;
          @In MyEntity myEntity;
          
          
          @PersistenceContext(unitName="DB1")
          EntityManager em;
          
          public void persistMyEntity()
           {
              //implement your business logic here
              log.info("MyEntity.persistMyEntity() action called with: #{myEntity.id}");
              
              em.persist(myEntity);
      
           }
      }