Camel-Mybatis Open session Exception - java

I'm using Camel-Mybatis version 2.12.0.redhat-610379, when we trying to start the bundle thru karaf container the following exception throws. Please advice.
org.apache.ibatis.exceptions.PersistenceException:
Error opening session. Cause: java.lang.NullPointerException
Cause: java.lang.NullPointerException
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)[280:org.mybatis.mybatis:3.2.5]
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:88)[280:org.mybatis.mybatis:3.2.5]
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:43)[280:org.mybatis.mybatis:3.2.5]
at org.apache.camel.component.mybatis.MyBatisProducer.process(MyBatisProducer.java:51)[282:org.apache.camel.camel-mybatis:2.12.0.redhat-611412]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:279)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.DefaultErrorHandler.process(DefaultErrorHandler.java:56)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:166)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:99)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processByErrorHandler(TransactionErrorHandler.java:218)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler$1.doInTransactionWithoutResult(TransactionErrorHandler.java:181)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.springframework.transaction.support.TransactionCallbackWithoutResult.doInTransaction(TransactionCallbackWithoutResult.java:33)[149:org.apache.servicemix.bundles.spring-tx:3.2.9.RELEASE_1]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:131)[149:org.apache.servicemix.bundles.spring-tx:3.2.9.RELEASE_1]
at org.apache.camel.spring.spi.TransactionErrorHandler.doInTransactionTemplate(TransactionErrorHandler.java:174)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.processInTransaction(TransactionErrorHandler.java:134)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:103)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.spring.spi.TransactionErrorHandler.process(TransactionErrorHandler.java:112)[150:org.apache.camel.camel-spring:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.timer.TimerConsumer.sendTimerExchange(TimerConsumer.java:147)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at org.apache.camel.component.timer.TimerConsumer$1.run(TimerConsumer.java:69)[144:org.apache.camel.camel-core:2.12.0.redhat-611412]
at java.util.TimerThread.mainLoop(Timer.java:555)[:1.7.0_01]
at java.util.TimerThread.run(Timer.java:505)[:1.7.0_01]
Caused by: java.lang.NullPointerException
at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:83)[280:org.mybatis.mybatis:3.2.5]
... 32 more
Bean.xml
<bean id="ds" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="oracle.jdbc.driver.OracleDriver"/>
<property name="jdbcUrl" value=""/>
<property name="user" value=""/>
<property name="password" value="" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<argument ref="ds" />
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="mybatisConfig" class="org.springframework.core.io.ClassPathResource">
<argument value="SqlMapConfig.xml" />
</bean>
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" ref="mybatisConfig"/>
<property name="mapperLocations">
<array value-type="org.springframework.core.io.Resource">
<bean class="org.springframework.core.io.ClassPathResource">
<argument value="mappings/QueryMessaging.xml" />
</bean>
</array>
</property>
</bean>
<bean id="sqlSessionFactory" class="org.apache.ibatis.session.SqlSessionFactory" factory-ref="sqlSessionFactoryBean"
factory-method="getObject" />
<bean id="myBatis" class="org.apache.camel.component.mybatis.MyBatisComponent">
<property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="txManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>

Connections and configurations are created properly, the bug I have made was in bean.xml i have used myBatis bean id, and camel route i have type as mybatis, due to case-sensitive, no environment was created, sorry for that.

Related

Camunda - why is process engine not getting created?

I am trying to integrate the BPMN tool : camunda in my app . I have been using the camunda docs here : https://docs.camunda.org/stable/guides/getting-started-guides/spring-framework/#set-up/application-context for that purpose .
I have added the application context related information as it has been mentioned in there :
<bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<property name="targetDataSource">
<bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.h2.Driver" />
<property name="url"
value="jdbc:h2:mem:process-engine;DB_CLOSE_DELAY=1000" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="processEngineConfiguration" class="org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration">
<property name="processEngineName" value="engine" />
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="transactionManager" />
<property name="databaseSchemaUpdate" value="true" />
<property name="jobExecutorActivate" value="false" />
</bean>
<bean id="processEngine" class="org.camunda.bpm.engine.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
<bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
<bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
But during build I am getting this error :
Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.camunda.bpm.engine.ProcessEngineException: Error while building ibatis SqlSessionFactory: Cause: org.xml.sax.SAXParseException; lineNumber: 95; columnNumber: 12; The content of element type "if" must match "(include|trim|where|set|foreach|choose|if)".
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans.jar:4.3.4.RELEASE]
Can someone please let me know what mistake I am making here ?
Any help will be greatly appreciated .
Camunda 7.3.0 uses mybatis 3.2.8 as per the project BOM.
You are using mybatis 3.2.2 which possibly causes a dependency version mismatch. Try updating your project mybatis dependencies to match the ones in your Camunda version.

Change the default datasource in spring batch

I want to use mysql database in spring batch application. Where should I keep my XML file with the details of datasource.
currently i have kept the env-context.xml in src/main/resources/META-INF/batch/override/manager
Content of env-context.xml:
<!-- connect to database -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/demo_db" />
<property name="username" value="testuser" />
<property name="password" value="12345" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
The common approach is to put this kind of configuration parameters into a properties file in order to externalize them as they will change from one environment to another.
It can be done as next:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:datasource.properties</value>
</property>
</bean>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${datasource.driver}" />
<property name="url" value="${datasource.url}" />
<property name="username" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
Then you put your file datasource.properties into the classpath, this file will have a content of type:
datasource.driver=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://localhost:3306/demo_db
datasource.username=testuser
datasource.password=12345

How to setup xa datasource using Spring and weblogic

I am having an issue creating xa datasources in spring 4.0.
I have setup my datasources in weblogic using an xa driver.
I then added added jndi-lookups for the data sources in spring:
<jee:jndi-lookup id="dataSourceOne" jndi-name="/jdbc/XAONE" resource-ref="true" />
<jee:jndi-lookup id="dataSourceTwo" jndi-name="/jdbc/XATWO" resource-ref="true" />
I have then created the configuration for the entity managers:
<bean id="emfone" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceOne" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="packagesToScan" value="..." />
</bean>
<bean id="emftwo"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSourceTwo" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
<property name="packagesToScan" value="..." />
</bean>
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE" />
<property name="showSql" value="true" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
</bean>
After this I have my transaction manager configured:
<tx:annotation-driven />
<tx:jta-transaction-manager />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emfone" />
<qualifier value="tmOne"/>
</bean>
<bean id="docTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emftwo" />
<qualifier value="tmTwo"/>
</bean>
I have a service class method annotated with #Transactional that calls a DAO. The DAO uses both entity managers for persisting data.
When the DAO tries to persist using the emftwo a no transaction in progress error is thrown. Does anybody know where I am going wrong?
Thanks,

ClassNotFoundException: org.hibernate.hql.internal.ast.HqlToken even after adding classic.ClassicQueryTranslatorFactory [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
org.hibernate.HibernateException: could not instantiate QueryTranslatorFactory: org.hibernate.hql.classic.ClassicQueryTransactionFactory
I am using Hibernate 4, Spring 3 and JSF 2.0. While running jsf page I am getting
org.hibernate.QueryException: ClassNotFoundException:
org.hibernate.hql.internal.ast.HqlToken [select generatedAlias0 from
net.test.model.Request as generatedAlias0]
I already have the following under hibernate properties in applicationContext.xml
<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.
ClassicQueryTranslatorFactory
</prop>
Please note that I have added org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean and org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter, I suspect that after adding this I was again getting org.hibernate.QueryException: ClassNotFoundException
My question what is the equivalent of ClassicQueryTranslatorFactory for spring properties?
If no such properties how could I resolve this?
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- Spring view scope customized -->
<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="view">
<bean class="org.primefaces.spring.scope.ViewScope" />
</entry>
</map>
</property>
</bean>
<context:component-scan base-package="net.test" />
<!-- Data Source Declaration -->
<bean id="DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="oracle.jdbc" />
<property name="jdbcUrl"
value="jdbc:oracle:thin:#server:1521:orcl" />
<property name="user" value="scott" />
<property name="password" value="tiger" />
<property name="maxPoolSize" value="10" />
<property name="maxStatements" value="0" />
<property name="minPoolSize" value="5" />
</bean>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<!-- JPA Entity Manager Factory -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="packagesToScan" value="net.test.model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="false" />
<property name="generateDdl" value="false" />
<property name="databasePlatform" value="${jdbc.dialectClass}" />
</bean>
</property>
</bean>
<bean id="defaultLobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
<!-- Session Factory Declaration -->
<bean id="SessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="DataSource" />
<property name="annotatedClasses">
<list>
<value>net.test.model.Request</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.query.factory_class">org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory
</prop>
</props>
</property>
</bean>
<!-- Enable the configuration of transactional behavior based on annotations
<tx:annotation-driven transaction-manager="txManager" />-->
<!-- Transaction Manager is defined
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory" />
</bean>-->
<!-- Transaction Config -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="SessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<tx:annotation-driven transaction-manager="txManager"/>
<context:annotation-config/>
<bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled" value="true" />
<property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" />
</bean>
<bean name="ehCacheManagerMBean"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean" />
<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
<property name="server" ref="mbeanServer" />
<property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>
<property name="beans">
<map>
<entry key="SpringBeans:name=hibernateStatisticsMBean" value-ref="hibernateStatisticsMBean" />
<entry key="SpringBeans:name=ehCacheManagerMBean" value-ref="ehCacheManagerMBean" />
</map>
</property>
</bean>
</beans>
edit modules/org/antlr/main/module.xml by adding the line <module name="org.hibernate" optional="true"/> inside the <dependencies> section. The issue must be resolved.
Thank you.
This issue has been resolved by doing the following
Use antlr 2.7.6 version which is compatible with Hibernate, add a reference in setDomainEnv.cmd
set CLASSPATH=\maven\repo\antlr\antlr\2.7.6\antlr-2.7.6.jar;%CLASSPATH%
More information here
Thanks

ReloadingPropertyPlaceholderConfigurer

For some reason the ReloadablePropertiesFactoryBean doens't seem to do what I expect. When I change a property in the test.properties file I get a log message saying:
9979 [timer] INFO com.krest.core.properties.ReloadablePropertiesFactoryBean - Reloading Properties...
But for some reason nothing happens. The old property value is still set on my test bean. Does anybody know why this is? I use Spring 3 and my configuration looks like this:
<bean id="configproperties"
class="com.krest.core.properties.ReloadablePropertiesFactoryBean">
<property name="location"
value="classpath:test.properties" />
</bean>
<bean id="propertyConfigurer"
class="com.krest.core.properties.ReloadingPropertyPlaceholderConfigurer">
<property name="properties" ref="configproperties" />
<property name="reloadingPlaceholderPrefix" value="rel{" />
<property name="reloadingPlaceholderSuffix" value="}" />
</bean>
<bean id="mybean" class="nl.mycompany.TestBean">
<property name="message" value="rel{timer-delay}" />
</bean>
<!-- regularly reload property files. -->
<bean id="timer" class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<bean id="reloadProperties"
class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="period" value="1000" />
<property name="runnable">
<bean class="com.krest.core.properties.ReloadConfiguration">
<property name="reconfigurableBeans">
<list>
<ref bean="configproperties" />
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>

Categories