1 Reply Latest reply on May 25, 2011 6:52 AM by davidmiller

    Error with database in JBoss Embedded

    davidmiller

      Hi All,

       

      hope you can help me.

       

      I'm trying to setup Seam integration testing with TestNG pointing to a SQL server database.  It's booting up the JBoss embedded server, but end up throwing out an org.jboss.InstantiationException.  The root cause seems to be a java.sql.SQLException: Invalid object name 'location'.

       

      I'm getting this error via the TestNG plugin in JBoss Developer Studio, and the same error if I run the test via Ant(although less verbose), but there is one slight difference when I run them.

      If I run the test with Ant I need the *-ds.xml file in the deploy directory of the embedded JBoss, but when I run TestNG with the Eclipse plugin it says the datasource is already configured, so I have to remove it. 

      So where does the Eclipse TestNG plugin pick up the datasource from?

       

      Thats my first question, but I'm more confused about how the errors is being produced as it appears to be a Hibernate problem, or indeed a problem with pointing to an SQL Server.  But the persistance.xml and datasource should be the same as running on the normal application server.

       

      So here is the error I am getting:

       

      org.jboss.seam.InstantiationException: Could not instantiate Seam component: countryList
          at org.jboss.seam.Component.newInstance(Component.java:2170)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:305)
          at org.jboss.seam.contexts.Contexts.startup(Contexts.java:279)
          at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:142)
          at org.jboss.seam.init.Initialization.init(Initialization.java:744)
          at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:919)
          at org.jboss.seam.mock.SeamTest.startSeam(SeamTest.java:58)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
          at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:525)
          at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:202)
          at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:130)
          at org.testng.SuiteRunner.privateRun(SuiteRunner.java:260)
          at org.testng.SuiteRunner.run(SuiteRunner.java:223)
          at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
          at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
          at org.testng.TestNG.runSuitesSequentially(TestNG.java:995)
          at org.testng.TestNG.runSuitesLocally(TestNG.java:920)
          at org.testng.TestNG.run(TestNG.java:856)
          at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
          at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
          at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)
      Caused by: javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
          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.localInvoke(StatefulContainer.java:261)
          at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:119)
          at $Proxy115.create(Unknown Source)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
          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:43)
          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.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
          at org.javassist.tmp.java.lang.Object_$$_javassist_seam_0.create(Object_$$_javassist_seam_0.java)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
          at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144)
          at org.jboss.seam.Component.callComponentMethod(Component.java:2275)
          at org.jboss.seam.Component.callCreateMethod(Component.java:2198)
          at org.jboss.seam.Component.newInstance(Component.java:2158)
          ... 24 more
      Caused by: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query
          at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637)
          at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74)
          at org.esi.cms.session.CountryListManager.create(CountryListManager.java:53)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          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:28)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
          at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
          at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:30)
          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 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          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:57)
          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)
          ... 63 more
      Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
          at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
          at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
          at org.hibernate.loader.Loader.doList(Loader.java:2223)
          at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
          at org.hibernate.loader.Loader.list(Loader.java:2099)
          at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
          at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
          at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
          at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)
          at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:65)
          ... 97 more
      Caused by: java.sql.SQLException: Invalid object name 'location'.
          at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:368)
          at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
          at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
          at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:632)
          at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:477)
          at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:776)
          at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:235)
          at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:187)
          at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
          at org.hibernate.loader.Loader.doQuery(Loader.java:674)
          at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
          at org.hibernate.loader.Loader.doList(Loader.java:2220)
          ... 104 more
      

       

      And here is my persistance.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="CMS" transaction-type="JTA">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>java:/CMSDatasource</jta-data-source>
      
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_catalog" value="CMS"/>
               <property name="hibernate.default_schema" value="dbo"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/CMSEntityManagerFactory"/>
            </properties>
         </persistence-unit>
          
      </persistence>
      

       

      The datasource file looks like this:

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
         
         <local-tx-datasource>
            <jndi-name>CMSDatasource</jndi-name>
            <use-java-context>true</use-java-context>
            <connection-url>jdbc:jtds:sqlserver://xxxx;DatabaseName=CMS</connection-url>
            <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
            <user-name>CMSUser</user-name>
            <password>xxxx</password>
         </local-tx-datasource>
          
      </datasources>
      
      

       

       

       

      So any help would be much appreciatted.

        • 1. Re: Error with database in JBoss Embedded
          davidmiller

          Finally got to the bottom of this, so will post my solution in the hope it will help someone else.

           

          It all came down to the datasource.  An SQL statement was failing and subsequently the components could not instantiate.  I was running it both through ant and the TestNG plugin and discovered that the TestNG plugin in Eclipse picks up the datasource from the META-INF directory within the test source.  This was set incorrectly.  I amended this to be correct and moved it to the bootstrap/deploy folder and it worked.

           

          Dave