0 Replies Latest reply on Apr 30, 2008 7:11 PM by Nicolai Abruzzese

    DBUnit test EJB, can't persist!

    Nicolai Abruzzese Newbie

      I've been trying to test the persistnce of my ejbs with no luck.
      I use a JBoss embedded for the testing.
      database.xml with my test data is ok! I can see my data in the test database.


      Thanks to all of you for your time!


      My base clas


      public class TestBase extends DBUnitSeamTest {
      
          @Override
          protected void prepareDBUnitOperations() {
              beforeTestOperations.add(new DataSetOperation("database.xml"));
          }
      
         
          protected void disableReferentialIntegrity(IDatabaseConnection con) {
              try {
                  con.getConnection().prepareStatement("set foreign_key_checks=0").execute();
              } catch (Exception ex) {
                  throw new RuntimeException(ex);
              }
          }
      
          
          protected void enableReferentialIntegrity(IDatabaseConnection con) {
              try {
                  con.getConnection().prepareStatement("set foreign_key_checks=1").execute();
              } catch (Exception ex) {
                  throw new RuntimeException(ex);
              }
          }
      
          @Override
          public void setDatasourceJndiName(String datasourceJndiName) {
              super.setDatasourceJndiName(datasourceJndiName);
          }
      
          @BeforeClass
          public void setDatasourceJndiName() {
              setDatasourceJndiName("java:/MySqlDS");
          }
      }


      My extended class:


      public class IdiomaAdministradorImplNgTest extends TestBase{
          
           @Test
          public void testIdiomaTest() throws Exception {
      
           
              String conversationId = new FacesRequest("idiomaNuevo.xhtml") {
      
      
                  @Override
                  protected void processValidations() throws Exception {
                      validateValue("#{idioma.codigo}", "ITA");
                      validateValue("#{idioma.nombre}", "Italiano");
      
                      assert !isValidationFailure();
                  }
      
                  @Override
                  protected void updateModelValues() throws Exception {
                      setValue("#{idioma.codigo}", "ITA");
                      setValue("#{idioma.nombre}", "Italiano");
      
                  }
      
                  @Override
                  protected void invokeApplication() {
                                  
                    invokeMethod("#{idiomaAdministrador.save}");
      
                  }
      
                  @Override
                  protected void renderResponse() throws Exception {
                      ListDataModel dataModel = (ListDataModel) getValue("#{idiomaLista}");
                      assert dataModel != null;
                      assert dataModel.getRowCount() == 3;
                      
                      System.out.println(getValue("#{idioma.codigo}") + " - " + getValue("#{idioma.nombre}"));
      
                  }
              }.run();
              System.out.println("IdiomaAdministradorImplNgTest......!");
           }
      }
      


      The error on 


      invokeMethod("#{idiomaAdministrador.guardar}");



      (persist name method of the EJB is in spanish)would be same as:


      invokeMethod("#{idiomaAdministrador.persist}");



      and the stacktrace:



      -------------------------------------------------------------------------------
      Test set: TestSuite
      -------------------------------------------------------------------------------
      Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 130.015 sec <<< FAILURE!
      testIdiomaTest(com.binariaconsultores.erp.ejb.parametros.internos.impl.IdiomaAdministradorImplNgTest)  Time elapsed: 0.672 sec  <<< FAILURE!
      java.lang.AssertionError: javax.el.ELException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.binariaconsultores.erp.dominio.parametros.internos.Idioma]
              at org.jboss.seam.mock.BaseSeamTest$Request.onException(BaseSeamTest.java:475)
              at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:526)
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
              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.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:44)
              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:514)
              at com.binariaconsultores.erp.ejb.parametros.internos.impl.IdiomaAdministradorImplNgTest.testIdiomaTest(IdiomaAdministradorImplNgTest.java:22)
      Caused by: javax.el.ELException: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.binariaconsultores.erp.dominio.parametros.internos.Idioma]
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:332)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:341)
              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:483)
              at com.binariaconsultores.erp.ejb.parametros.internos.impl.IdiomaAdministradorImplNgTest$1.invokeApplication(IdiomaAdministradorImplNgTest.java:43)
              at org.jboss.seam.mock.BaseSeamTest$Request.invokeApplicationPhase(BaseSeamTest.java:652)
              at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:598)
              at org.jboss.seam.mock.BaseSeamTest$Request.access$300(BaseSeamTest.java:185)
              at org.jboss.seam.mock.BaseSeamTest$Request$2.doFilter(BaseSeamTest.java:519)
              ... 41 more
      Caused by: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.binariaconsultores.erp.dominio.parametros.internos.Idioma]
              at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:63)
              at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
              at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:193)
              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.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:86)
              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.stateful.StatefulContainer.dynamicInvoke(StatefulContainer.java:372)
              at org.jboss.ejb3.remoting.IsLocalInterceptor.invokeLocal(IsLocalInterceptor.java:81)
              at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:139)
              at $Proxy145.guardar(Unknown Source)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              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.ejb.RemoveInterceptor.aroundInvoke(RemoveInterceptor.java:41)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:106)
              at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
              at org.javassist.tmp.java.lang.Object_$$_javassist_1.guardar(Object_$$_javassist_1.java)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:328)
              ... 51 more
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.binariaconsultores.erp.dominio.parametros.internos.Idioma]
              at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
              at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:219)
              at org.jboss.ejb3.entity.ExtendedEntityManager.persist(ExtendedEntityManager.java:101)
              at org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.persist(FullTextEntityManagerImpl.java:82)
              at org.jboss.seam.persistence.EntityManagerProxy.persist(EntityManagerProxy.java:135)
              at org.jboss.seam.framework.EntityHome.persist(EntityHome.java:50)
              at com.binariaconsultores.erp.ejb.parametros.internos.impl.IdiomaAdministradorImpl.guardar(IdiomaAdministradorImpl.java:172)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              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.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:46)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.persistence.ManagedEntityIdentityInterceptor.aroundInvoke(ManagedEntityIdentityInterceptor.java:48)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              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.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)
              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:106)
              at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
              at java.lang.reflect.Method.invoke(Method.java:597)
              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.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:71)
              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.invokeInOurTx(TxPolicy.java:79)
              ... 89 more
      Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [com.binariaconsultores.erp.dominio.parametros.internos.Idioma]
              at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
              at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
              at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
              at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
              at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
              at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
              at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
              at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
              at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
              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)
              ... 133 more
      Caused by: java.sql.SQLException: No value specified for parameter 6
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1056)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
              at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
              at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2179)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1996)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1940)
              at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1925)
              at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:250)
              at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
              at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
              ... 148 more