Caused by: java.lang.IllegalStateException: A JobRepository has not been set - java

Getting the below Exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncherRead' defined in class path resource [spring-beans.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: A JobRepository has not been set.
Caused by: java.lang.IllegalStateException: A JobRepository has not been set.
Code:
<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:aop="http://www.springframework.org/schema/aop"
xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="
http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:Application.properties" />
</bean>
<bean id="oracleSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="oraclesDataSource" />
<property name="mappingResources">
<list>
<value>persons.hbm.xml </value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<!-- <prop key="hibernate.autocommit">true</prop> <prop key="hibernate.connection.isolation">3</prop> -->
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</prop>
<prop key="hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
</props>
</property>
</bean>
<bean id="mysqlSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="mysqlDataSource" />
<property name="mappingResources">
<list>
<value>persons.hbm.xml </value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- <prop key="hibernate.autocommit">ture</prop> <prop key="hibernate.connection.isolation">3</prop> -->
<prop key="hibernate.current_session_context_class">jta</prop>
<prop key="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</prop>
<prop key="hibernate.transaction.manager_lookup_class">
com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup
</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
</props>
</property>
</bean>
<tx:annotation-driven proxy-target-class="true" />
<tx:jta-transaction-manager
transaction-manager="atomikosTransactionManager" />
<tx:annotation-driven transaction-manager="atomikosTransactionManager"
proxy-target-class="true" />
<bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager"
init-method="init" destroy-method="close">
<property name="forceShutdown" value="false" />
</bean>
<bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.J2eeUserTransaction">
<property name="transactionTimeout" value="300" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"
depends-on="atomikosTransactionManager,atomikosUserTransaction">
<property name="transactionManager" ref="atomikosTransactionManager" />
<property name="userTransaction" ref="atomikosUserTransaction" />
<property name="allowCustomIsolationLevels" value="true" />
</bean>
<bean id="mysqlDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>mySqlDataSource</value>
</property>
<property name="xaDataSourceClassName">
<value>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="databaseName">sys</prop>
<prop key="serverName">localhost</prop>
<prop key="port">3306</prop>
<prop key="user">root</prop>
<prop key="password">magesh123</prop>
<prop key="url">jdbc:mysql://localhost:3306/sys</prop>
</props>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
</bean>
<bean id="oraclesDataSource" class="com.atomikos.jdbc.AtomikosDataSourceBean"
init-method="init" destroy-method="close">
<property name="uniqueResourceName">
<value>OracleDataSource</value>
</property>
<property name="xaDataSourceClassName">
<value>oracle.jdbc.xa.client.OracleXADataSource</value>
</property>
<property name="xaProperties">
<props>
<prop key="databaseName">XE</prop>
<prop key="serverName">localhost</prop>
<!-- <prop key="port">1521</prop> -->
<prop key="user">system</prop>
<prop key="password">magesh123</prop>
<prop key="URL">jdbc:oracle:thin:#localhost:1521:XE</prop>
</props>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
</bean>
<bean id="persons" class="com.bnym.aal.poc.spring_jta.Persons">
</bean>
<bean id="App" class="com.bnym.aal.poc.spring_jta.App">
<property name="springJtaDaoClass" ref="springJtaDaoClass" />
</bean>
<bean id="springJtaDaoClass" class="com.bnym.aal.poc.spring_jta.springJtaDaoClass">
<property name="oracleSessionFactory" ref="oracleSessionFactory" />
<property name="mysqlSessionFactory" ref="mysqlSessionFactory" />
<property name="atomikosTransactionManager" ref="transactionManager" />
<property name="persons" ref="persons" />
</bean>
<bean id="customItemReader" class="com.bnym.aal.poc.spring_jta.customItemReader">
<property name="oracleSessionFactory" ref="oracleSessionFactory" />
</bean>
<bean id="customItemWriter" class="com.bnym.aal.poc.spring_jta.customItemWriter">
<property name="mysqlSessionFactory" ref="mysqlSessionFactory" />
</bean>
<bean id="customProcessor" class="com.bnym.aal.poc.spring_jta.customItemProcessor">
</bean>
<batch:job id="jobRead" job-repository="jobRepository">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="customItemReader" processor="customProcessor"
writer="customItemWriter" commit-interval="5" />
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jobLauncherRead"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
</bean>

Related

Unable to connect to database after migrating to Hibernate 4

I am trying to update hibernate from 3.6.10.Final to 4.3.6.Final. With 3.6.10 everything worked fine. I renamed the changed classes to the new classnames and get no errors on that side, but when I run the webapplication I get an error:
2015-06-12 10:44:35.345 ERROR SchemaUpdate:201 - HHH000319: Could not get database metadata
java.sql.SQLException: Connections could not be acquired from the underlying database!
With hibernate 3.6.10 the application-context.xml looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!--Annotation based Spring config -->
<bean id="namingStrategy" class="org.hibernate.cfg.ImprovedNamingStrategy" />
<context:component-scan base-package="nl.drs.esbcollector" />
<bean
class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<bean class="org.springframework.core.io.FileSystemResource">
<constructor-arg>
<jee:jndi-lookup jndi-name="java:comp/env/ESBCollectorConf" />
</constructor-arg>
</bean>
</property>
</bean>
<bean id="env" class="java.lang.String">
<constructor-arg>
<value>${general.env}</value>
</constructor-arg>
</bean>
<!-- Datasource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${database.driver}"></property>
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="testConnectionOnCheckout" value="true" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="namingStrategy" ref="namingStrategy" />
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="packagesToScan" value="nl.drs.esbcollector" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.order_inserts">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.max_size">50</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.idle_test_period">100</prop>
</props>
</property>
</bean>
<!-- Transactions -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="threadPoolExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="15" />
<property name="keepAliveSeconds" value="60" />
</bean>
<!-- <bean name="cleanUpJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass"
value="nl.drs.esbcollector.controller.tasks.DataCleanUpJob" />
</bean>
Cron Trigger
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="cleanUpJob" />
<property name="cronExpression" value="0/30 * * * * ?" />
</bean>
<bean id="schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean> -->
<bean name="complexJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="nl.drs.esbcollector.controller.tasks.DataCleanUpJob" />
<property name="durability" value="true" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="complexJobDetail" />
<property name="cronExpression" value="0/30 * * * * ?" />
</bean>
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="complexJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean>
<tx:annotation-driven />
</beans>
And I changed this to:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!--Annotation based Spring config -->
<bean id="namingStrategy" class="org.hibernate.cfg.ImprovedNamingStrategy" />
<context:component-scan base-package="nl.drs.esbcollector" />
<bean
class="org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<bean class="org.springframework.core.io.FileSystemResource">
<constructor-arg>
<jee:jndi-lookup jndi-name="java:comp/env/ESBCollectorConf" />
</constructor-arg>
</bean>
</property>
</bean>
<bean id="env" class="java.lang.String">
<constructor-arg>
<value>${general.env}</value>
</constructor-arg>
</bean>
<!-- Datasource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${database.driver}"></property>
<property name="jdbcUrl" value="${database.url}" />
<property name="user" value="${database.username}" />
<property name="password" value="${database.password}" />
<property name="testConnectionOnCheckout" value="true" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="nl.drs.esbcollector" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="hibernate.order_inserts">true</prop>
<prop key="hibernate.order_updates">true</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
</prop>
<prop key="show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.max_size">50</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.idle_test_period">100</prop>
</props>
</property>
</bean>
<!-- Transactions -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="threadPoolExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5" />
<property name="maxPoolSize" value="15" />
<property name="keepAliveSeconds" value="60" />
</bean>
<!-- <bean name="cleanUpJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="nl.drs.esbcollector.controller.tasks.DataCleanUpJob"
/> </bean> Cron Trigger <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="cleanUpJob" /> <property name="cronExpression"
value="0/30 * * * * ?" /> </bean> <bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers"> <list> <ref bean="cronTrigger" /> </list> </property>
<property name="applicationContextSchedulerContextKey"> <value>applicationContext</value>
</property> </bean> -->
<bean name="complexJobDetail"
class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass"
value="nl.drs.esbcollector.controller.tasks.DataCleanUpJob" />
<property name="durability" value="true" />
</bean>
<bean id="cronTrigger"
class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="complexJobDetail" />
<property name="cronExpression" value="0/30 * * * * ?" />
</bean>
<bean id="schedulerFactory"
class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="complexJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
<property name="applicationContextSchedulerContextKey">
<value>applicationContext</value>
</property>
</bean>
<tx:annotation-driven />
</beans>
In short
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
Has been changed to
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
And
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
to
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
Did I mis some change which is causing the connection to fail now?
You need to remove the following properties:
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
<prop key="hibernate.c3p0.min_size">3</prop>
<prop key="hibernate.c3p0.max_size">50</prop>
<prop key="hibernate.c3p0.timeout">1800</prop>
<prop key="hibernate.c3p0.idle_test_period">100</prop>
Hibernate already uses the external dataSource so it doesn't use the internal ConnectionProvider mechanism.
You are getting an exception, because Hibernate might ignore the properly configured dataSource and try to use the C3P0ConnectionProvider, for which you don't supply an URL, user, password.

Exit program on Spring jpa/Hibernate connection exception

I want my program to exit if it cannot connect to the database on startup. Currently this connection is setup using the following:
application-context.xml
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>${db.driver}</value>
</property>
<property name="url">
<value>${db.url}</value>
</property>
<property name="username">
<value>${db.username}</value>
</property>
<property name="password">
<value>${db.password}</value>
</property>
</bean>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan" value="com.template" />
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.ejb.naming_strategy">${naming_strategy}</prop>
<prop key="hibernate.connection.autoReconnect">true</prop>
<prop key="hibernate.connection.autoReconnectForPools">true</prop>
<prop key="hibernate.connection.check-valid-connection-sql">SELECT 1</prop>
<prop key="hibernate.connection.failOverReadOnly">false</prop>
<prop key="hibernate.connection.maxReconnects">${maxreconnects}</prop>
<prop key="hibernate.connection.initialTimeout">${reconnect.interval}</prop>
</props>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
Repository:
#Repository
public interface Repository extends CrudRepository<Object, String> {
}
It's not obvious where I should place code to catch the runtime exceptions created by the connection failure. Are there any other settings I can use to exit if the database doesn't exist.
Usually, spring will stop, if it could not create a bean at startup. If DB connection fails, then it will stop automatically anyway. Do you want to catch that exception, and do something before exit ?

Spring Hibernate configuration issue: org.springframework.beans.factory.BeanCreationException

I am trying to create spring+hibernate application, after added hibernate configurations I am getting org.springframework.beans.factory.BeanCreationException while starting tomcat server:
Error creating bean with name 'dataSource' defined in ServletContext
resource [/WEB-INF/hibernate-config.xml]: Initialization of bean
failed; nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.AnnotationUtils.getAnnotation(Ljava/lang/reflect/AnnotatedElement;Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
hibernate-config.xml
<context:component-scan base-package="com.test.common">
</context:component-scan>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.test.common.model.CompanyTypes</value>
<value>com.test.common.model.Employee</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> -->
<!--prop key="current_session_context_class">thread</prop-->
<!-- <prop key="hibernate.connection.release_mode">on_close</prop> -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/testDB" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
jars included:
please guide, thanks in advance..

Unable to start hibernate session factory bean

Here is my hibernate config
<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.h2.Driver"/>
<property name="url" value="jdbc:h2:mem:/localhost/testDB"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="packagesToScan" value="sample.model"/>
<property name="annotatedPackages">
<list>
<value>sample.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
</props>
</property>
</bean>
I included this dependency
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
Here is the exception
Caused by: java.lang.IllegalStateException: Expected method not found: java.lang.NoSuchMethodException: org.hibernate.cfg.Configuration.addAnnotatedClass(java.lang.Class)
at org.springframework.util.ClassUtils.getMethod(ClassUtils.java:627)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.<clinit>(LocalSessionFactoryBuilder.java:79)
... 39 more
What am I missing here?
It looks like your hibernate annotations jar file is the incorrect version.
You should already have hibernate-core as a dependency. If so you can comment out your hibernate-annotations dependency in your POM file.
The solution was to use hibernate 3 and Adding this
<prop key="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</prop>
So the final config is
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="packagesToScan" value="sample.model"/>
<property name="annotatedPackages">
<list>
<value>sample.model</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">create</prop>
<prop key="hibernate.current_session_context_class">org.hibernate.context.ThreadLocalSessionContext</prop>
</props>
</property>
</bean>

Quartz NotSerializableException Exception

Im using quartz 1.5.2 with spring 3.0.5 version. When i try to get the scheduler context with jdbc store type quartz, im facing NotSerializableException. I have done my research to get it done but i couldnt managed to get over it. Im out of ideas.
Here is the scheduler configuration.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="taskExecutor"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize">
<value>${middleware.taskExecutor.corePoolSize}</value>
</property>
<property name="maxPoolSize">
<value>${middleware.taskExecutor.maxPoolSize}</value>
</property>
<property name="queueCapacity">
<value>${middleware.taskExecutor.queueCapacity}</value>
</property>
</bean>
<bean id="emailService" class="EmailServiceImpl">
</bean>
<bean id="emailSenderTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="emailSenderJob"/>
<property name="startDelay">
<value>${middleware.portingTrigger.startDelay}</value>
</property>
<property name="repeatInterval">
<value>${middleware.portingTrigger.repeatInterval}</value>
</property>
</bean>
<bean id="emailSenderJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.alcatel.lucent.tr.yoda.middleware.job.EmailSenderJob"/>
<property name="jobDataAsMap">
<map>
<entry key="taskExecuter" value-ref="taskExecutor"/>
<entry key="emailService">
<ref bean="emailService"/>
</entry>
</map>
</property>
</bean>
<bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="schedulerContextAsMap">
<map>
<entry key="emailService">
<ref bean="emailService"/>
</entry>
</map>
</property>
<property name="autoStartup" value="true"/>
<property name="triggers">
<list>
<ref bean="emailSenderTrigger"/>
</list>
</property>
<property name="quartzProperties">
<props>
<prop key="org.quartz.scheduler.instanceName">DefaultQuartzScheduler</prop>
<prop key="org.quartz.scheduler.rmi.export">false</prop>
<prop key="org.quartz.scheduler.rmi.proxy">false</prop>
<prop key="org.quartz.scheduler.xaTransacted">false</prop>
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
<prop key="org.quartz.threadPool.threadCount">5</prop>
<prop key="org.quartz.threadPool.threadPriority">4</prop>
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreCMT</prop>
<!--<prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>-->
<prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
<prop key="org.quartz.jobStore.dataSource">QUARTZ</prop>
<prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
<prop key="org.quartz.jobStore.nonManagedTXDataSource">QUARTZ_NO_TX</prop>
<prop key="org.quartz.dataSource.QUARTZ.jndiURL">java:QuartzDS</prop>
<prop key="org.quartz.dataSource.QUARTZ_NO_TX.jndiURL">java:QuartzNoTxDS</prop>
</props>
</property>
</bean>
What should i do? Thanks in advance.
Use inner classes. No serialization is required.
http://shyarmal.blogspot.com/2011/07/quartz-20-schedule-cron-with-spring.html
EmailSenderJob and all of its members need to implement Serializable.

Categories