2 Replies Latest reply on Aug 21, 2014 8:56 AM by Ramesh Reddy

    Embedded Teiid Server in Spring, and Hibernate on Top

    Ogi Prayogo Newbie

      Hello all,

       

      I am starting a project with a the following stack

      - Spring 4.1

      - Hibernate 4.3.5

      - Teiid 8.8

       

      my bean setup is as below, and basically I have 2 beans as data sources, and using Arjuna Transaction Manager.

       

      <bean id="teiidServer" class="com.asterx.medirecords.utils.servlet.TeiidServer" init-method="init">

          <property name="dataSourceOne" ref="dataSourceOne"/>

          <property name="dataSourceTwo" ref="dataSourceTwo" />

          <property name="transactionManager" ref="arjunaTransactionManager" />

          <property name="bindAddress" value="${teiid.database.serverName}"/>

          <property name="port" value="${teiid.database.portNumber}"/>

      </bean>

       

      <bean id="teiidDatasource" class="org.teiid.jdbc.TeiidDataSource">

          <property name="serverName" value="${teiid.database.serverName}"/>

          <property name="portNumber" value="${teiid.database.portNumber}"/>

          <property name="databaseName" value="${teiid.database.databaseName}"/>

          <property name="databaseVersion" value="${teiid.database.databaseVersion}"/>

      </bean>


      The init method in TeiidServer.java is as in the attached file

       

      When we run my unit test to get the data from, we get the following error:

       

      org.springframework.orm.hibernate4.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [n/a]; SQL state [38000]; error code [0]; could not extract ResultSet; nested exception is org.hibernate.exception.GenericJDBCException: could not extract ResultSet

          at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:170)

          at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:343)

          at org.springframework.orm.hibernate4.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:308)

          at org.springframework.orm.hibernate4.HibernateTemplate.get(HibernateTemplate.java:418)

          at org.springframework.orm.hibernate4.HibernateTemplate.get(HibernateTemplate.java:411)

          at com.asterx.medirecords.patient.dao.LetterTemplateDAOHib.getLetterTemplate(LetterTemplateDAOHib.java:18)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)

          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)

          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)

          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)

          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:266)

          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)

          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

          at com.sun.proxy.$Proxy28.getLetterTemplate(Unknown Source)

          at com.asterx.medirecords.patient.dao.LetterTemplateDAOHibTest.getLetterTemplateTest(LetterTemplateDAOHibTest.java:45)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)

          at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

          at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)

          at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

          at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72)

          at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:81)

          at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)

          at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)

          at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)

          at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)

          at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)

          at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)

          at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)

          at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)

          at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)

          at org.junit.runners.ParentRunner.run(ParentRunner.java:309)

          at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)

          at org.junit.runner.JUnitCore.run(JUnitCore.java:160)

          at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)

          at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:202)

          at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:65)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

          at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

      Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet

          at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)

          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)

          at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)

          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:89)

          at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:449)

          at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:202)

          at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)

          at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)

          at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186)

          at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4126)

          at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502)

          at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467)

          at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)

          at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274)

          at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)

          at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)

          at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)

          at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2551)

          at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)

          at org.springframework.orm.hibernate4.HibernateTemplate$1.doInHibernate(HibernateTemplate.java:426)

          at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340)

          ... 50 more

      Caused by: org.teiid.jdbc.TeiidSQLException: org.teiid.core.TeiidException

          at org.teiid.jdbc.TeiidSQLException.create(TeiidSQLException.java:135)

          at org.teiid.jdbc.TeiidSQLException.create(TeiidSQLException.java:71)

          at org.teiid.jdbc.StatementImpl.postReceiveResults(StatementImpl.java:667)

          at org.teiid.jdbc.StatementImpl.access$100(StatementImpl.java:63)

          at org.teiid.jdbc.StatementImpl$2.onCompletion(StatementImpl.java:515)

          at org.teiid.client.util.ResultsFuture.done(ResultsFuture.java:135)

          at org.teiid.client.util.ResultsFuture.access$200(ResultsFuture.java:40)

          at org.teiid.client.util.ResultsFuture$1.receiveResults(ResultsFuture.java:79)

          at org.teiid.net.socket.SocketServerInstanceImpl.receivedMessage(SocketServerInstanceImpl.java:264)

          at org.teiid.net.socket.SocketServerInstanceImpl.read(SocketServerInstanceImpl.java:302)

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

          at org.teiid.net.socket.SocketServerConnectionFactory$ShutdownHandler.invoke(SocketServerConnectionFactory.java:98)

          at com.sun.proxy.$Proxy24.read(Unknown Source)

          at org.teiid.net.socket.SocketServerInstanceImpl$RemoteInvocationHandler$1.get(SocketServerInstanceImpl.java:401)

          at org.teiid.jdbc.StatementImpl.executeSql(StatementImpl.java:524)

          at org.teiid.jdbc.PreparedStatementImpl.executeQuery(PreparedStatementImpl.java:261)

          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)

          ... 67 more

      Caused by: org.teiid.core.TeiidException

          at org.teiid.client.ResultsMessage.setException(ResultsMessage.java:194)

          at org.teiid.dqp.internal.process.RequestWorkItem.sendError(RequestWorkItem.java:1005)

          at org.teiid.dqp.internal.process.RequestWorkItem.close(RequestWorkItem.java:552)

          at org.teiid.dqp.internal.process.RequestWorkItem.process(RequestWorkItem.java:352)

          at org.teiid.dqp.internal.process.AbstractWorkItem.run(AbstractWorkItem.java:51)

          at org.teiid.dqp.internal.process.RequestWorkItem.run(RequestWorkItem.java:254)

          at org.teiid.dqp.internal.process.DQPWorkContext.runInContext(DQPWorkContext.java:274)

          at org.teiid.dqp.internal.process.ThreadReuseExecutor$RunnableWrapper.run(ThreadReuseExecutor.java:119)

          at org.teiid.dqp.internal.process.ThreadReuseExecutor$3.run(ThreadReuseExecutor.java:214)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

          at java.lang.Thread.run(Thread.java:745)

      Caused by: java.lang.NullPointerException

          at org.teiid.translator.jdbc.JDBCExecutionFactory.getDatabaseCalendar(JDBCExecutionFactory.java:531)

          at org.teiid.translator.jdbc.JDBCExecutionFactory.retrieveValue(JDBCExecutionFactory.java:966)

          at org.teiid.translator.jdbc.sybase.BaseSybaseExecutionFactory.retrieveValue(BaseSybaseExecutionFactory.java:124)

          at org.teiid.translator.jdbc.JDBCQueryExecution.next(JDBCQueryExecution.java:344)

          at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.handleBatch(ConnectorWorkItem.java:385)

          at org.teiid.dqp.internal.datamgr.ConnectorWorkItem.more(ConnectorWorkItem.java:203)

          at org.teiid.dqp.internal.process.DataTierTupleSource.getResults(DataTierTupleSource.java:301)

          at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:110)

          at org.teiid.dqp.internal.process.DataTierTupleSource$1.call(DataTierTupleSource.java:107)

          at java.util.concurrent.FutureTask.run(FutureTask.java:262)

          at org.teiid.dqp.internal.process.FutureWork.run(FutureWork.java:58)

          ... 6 more

       

       

      We are running out of clues at the moment as for why the error occured, any help would be greatly appreciated.

       

      I attached the full spring config file, vdb.xml, and TeiidServer java

        • 1. Re: Embedded Teiid Server in Spring, and Hibernate on Top
          Steven Hawkins Master

          Make sure that start is called on both translators.  We assume that their lifecylce is managed by the caller when they are added as instances.

          • 2. Re: Embedded Teiid Server in Spring, and Hibernate on Top
            Ramesh Reddy Master

            Ogi,

             

            From your project it looks like you are same person who was asking questions about multi-source couple days ago in the #teiid IRC channel. The reason your multi-source did not work due to the fact that, in multi-source your schema needs to be exactly same on both data sources including the schema name. In your case except for schema name, everything else was same, also these two separate schemas were served from same database instance. Even though, Teiid is making two different calls through two different connections, since they were on same machine and user has access to both schemas, the calls  were directed to same database, thus duplicate results. Try moving the ds-two to a different machine, with exact schema then you will see correct results.

             

            Ramesh..