We help IT Professionals succeed at work.
Get Started

spring, quartz, jpa, hibernate

faihandhope asked
Last Modified: 2013-11-24
Hello experts, I hope you can help me.

I am using quartz to run jobs in a web application.  Works fine if the job is to just print "say hello", and will trigger every 5 seconds.

But when I modified the job, and added a call to the EntityManager service to get the data. It does not run at all.

Below is the code.  Also the applicatonContext.xml file where spring is referencing the job.

Any help, is appreciated.
My job is called TestQuartz.java
public class TestQuartz extends QuartzJobBean   {
	   private Collection<EmailEntity> emails;
	   private EmailEntity email;
                   	   private EmailService es;
	    public void setEs(EmailService es) {
		this.es = es;
    protected void executeInternal(JobExecutionContext ctx)  throws JobExecutionException {
	//this does not work at all
   	emails = es.findAll(); 
   	if (emails.size() > 0) {
   		System.out.println("got data");
	 System.out.println("Hello from Spring and Quartz");
applicatonContext.xml :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSourceSQL"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="false"/>
                <property name="generateDdl" value="true"/>
    <bean id="dataSourceSQL"
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:hsql://localhost/xdb"/>
        <property name="username" value="sa"/>
    <bean id="transactionManager"
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="TestQuartz"/>
  <property name="jobDataAsMap">
      <entry key="timeout" value="5"/>
      <entry key="es" value="com.vaannila.service.admin.EmailService"/>
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:component-scan base-package="com.vaannila"/>

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 16 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE