Announcement Announcement Module
No announcement yet.
Entities not persisted with Quartz Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Entities not persisted with Quartz

    Hi everyone.

    My post is relative to quartz and persistence.. but I think that the problem is with persistence, so I post it here!

    I have a Spring MVC application with two Quartz job. One of them is responsable of copy two tables from a mssql db to the mysql application db in order to keep them synchronized.

    I've tested my code in a junit test and it work fine. The first time launched the destination db is empty and it added all the entities. The next times it add the newest and update the changes.

    Now comes the problems.

    When I move my code in quartz and I run the job, this is executed without errors, but the entities aren't persisted! It can read the entities from the source database, but it cannot write in the destination db!

    I try it by injecting services, or directly DAOs, but nothing changes. Except the speed. Using services is more slow!

    Here is the code of my job
    public class AggiornaClientiJob extends QuartzJobBean  {
    public void init(JobExecutionContext ctx) throws SchedulerException {
    	log.debug("FundSearchMapRefreshJob - Setting properties ...");
    	SchedulerContext skedCtx = ctx.getScheduler().getContext();
    	setClienteI24Service((ClienteI24Service) skedCtx.get("clienteI24Service"));
    	setClienteService((ClienteService) skedCtx.get("clienteService"));
    	setPersonaService((PersonaService) skedCtx.get("personaService"));
    	if (this.clienteI24Service == null ) {
    		throw new SchedulerException("clienteI24Service cannot be null!");
    	if (this.clienteService == null ) {
    		throw new SchedulerException("clienteService cannot be null!");
    	if (this.personaService == null ) {
    		throw new SchedulerException("personaService cannot be null!");
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("quartz", "quartz"));
    	try {
    	} catch (SchedulerException e) {
    		log.error("FundSearchMapRefreshJob: exception", e);
            int clientiAggiunti = 0;
    	int clientiAggiornati = 0;
    	int personeAggiunte = 0;
    	int personeAggiornate = 0;"Ricerca clienti su I24");
    	final List<ClienteI24> clientiI24 = clienteI24Service.getAll();
  "Ricerca completata. Inizio sincronizzazione");
    	for (ClienteI24 clienteI24 : clientiI24){
    	    Persona personaPresente = personaService.get(clienteI24.getPersona().getId().longValue());
    		if (personaPresente == null){
    			Persona newPersona = new Persona();
    			BeanUtils.copyProperties(clienteI24.getPersona(), newPersona, new String[]{"id"});
    			personaPresente = newPersona;
    		else {
    			if(!personaEquals(clienteI24.getPersona(), personaPresente)){
    				Persona newPersona = new Persona();
    				BeanUtils.copyProperties(clienteI24.getPersona(), newPersona, new String[]{"id"});
    And in xml file i configure quartz
    <bean id="clienteI24Service" class="" />
    <bean id="clienteService" class="" />
    <bean id="personaService" class="" />
    <bean name="aggiornaClienti" class="org.springframework.scheduling.quartz.JobDetailBean">
      		<property name="jobClass" value="" />  		
    <bean id="aggiornaClientiTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
        	<property name="jobDetail" ref="aggiornaClienti" />
        	<property name="cronExpression" value="0 15 9,12,17,18,21 * * ?" />
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
                <ref bean="emailScadenzaInterventiApparecchiatureTrigger" />
                <ref bean="aggiornaClientiTrigger" />
       <!-- <property name="dataSource" ref="dataSource"/>  --> 
        <property name="applicationContextSchedulerContextKey">
    	<property name="schedulerContextAsMap">
             <entry key="clienteI24Service">
                <ref bean="clienteI24Service"/>
             <entry key="clienteService">
                <ref bean="clienteService"/>
             <entry key="personaService">
                <ref bean="personaService"/>
    <property name="configLocation">
    If someone have some suggestions...

    Thank you!

  • #2
    Looking at the log generated by Test and by Quartz the main difference is that:

    test has an AbstractFlushingEventListener, while quartz no!

    Any suggestions? thank you..