troubleshooting Question

spring, quartz, jpa, hibernate

Avatar of faihandhope
faihandhope asked on
Java EEJava
16 Comments1 Solution2246 ViewsLast Modified:
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"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd
    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
       class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
 
 
    <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>
        </property>
    </bean>
 
    <bean id="dataSourceSQL"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
        <property name="url" value="jdbc:hsqldb:hsql://localhost/xdb"/>
        <property name="username" value="sa"/>
     </bean>
 
    <bean id="transactionManager"
          class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>
 
<bean name="exampleJob" class="org.springframework.scheduling.quartz.JobDetailBean">
  <property name="jobClass" value="TestQuartz"/>
  <property name="jobDataAsMap">
    <map>
      <entry key="timeout" value="5"/>
      <entry key="es" value="com.vaannila.service.admin.EmailService"/>
    </map>
  </property>
</bean>
 
    <tx:annotation-driven transaction-manager="transactionManager"/>
    <context:annotation-config/>
    <context:component-scan base-package="com.vaannila"/>
  </beans>

Open in new window

ASKER CERTIFIED SOLUTION
faihandhope

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros