Announcement Announcement Module
Collapse
No announcement yet.
Entities not persisted with Quartz Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
    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!");
    	}
    }
    
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
    	SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("quartz", "quartz"));
    		
    
    	try {
    		init(context);
    	} catch (SchedulerException e) {
    		log.error("FundSearchMapRefreshJob: exception", e);
    	}
    
            int clientiAggiunti = 0;
    	int clientiAggiornati = 0;
    		
    	int personeAggiunte = 0;
    	int personeAggiornate = 0;
    	log.info("Ricerca clienti su I24");
    	final List<ClienteI24> clientiI24 = clienteI24Service.getAll();
    		
    	log.info("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"});
    				                 
                            newPersona.setId(clienteI24.getPersona().getId().longValue());
    			personaService.save(newPersona);
    			personaPresente = newPersona;
    			personeAggiunte++;
    		}
    		else {
    			if(!personaEquals(clienteI24.getPersona(), personaPresente)){
    				Persona newPersona = new Persona();
    				BeanUtils.copyProperties(clienteI24.getPersona(), newPersona, new String[]{"id"});
    			newPersona.setId(clienteI24.getPersona().getId().longValue());
    					personaService.merge(newPersona);
    					personeAggiornate++;
    				}
    			}
    ...............................
    And in xml file i configure quartz
    Code:
    <bean id="clienteI24Service" class="it.cpmapave.pm.service.i24.ClienteI24ServiceImpl" />
    <bean id="clienteService" class="it.cpmapave.pm.service.amministrazione.ClienteServiceImpl" />
    <bean id="personaService" class="it.cpmapave.pm.service.amministrazione.PersonaServiceImpl" />
    
    <bean name="aggiornaClienti" class="org.springframework.scheduling.quartz.JobDetailBean">
      		<property name="jobClass" value="it.cpmapave.pm.quartz.amministrazione.AggiornaClientiJob" />  		
    	</bean>
    
    <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>
    
    <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="emailScadenzaInterventiApparecchiatureTrigger" />
                <ref bean="aggiornaClientiTrigger" />
            </list>
        </property>
       <!-- <property name="dataSource" ref="dataSource"/>  --> 
        <property name="applicationContextSchedulerContextKey">
    			<value>applicationContext</value>
    	</property>
    	<property name="schedulerContextAsMap">
          <map>
             <entry key="clienteI24Service">
                <ref bean="clienteI24Service"/>
             </entry>
             <entry key="clienteService">
                <ref bean="clienteService"/>
             </entry>
             <entry key="personaService">
                <ref bean="personaService"/>
             </entry>
          </map>
       </property>
    <property name="configLocation">
    		<value>/WEB-INF/spring/quartz.properties</value>
    	</property> 
    </bean>
    If someone have some suggestions...

    Thank you!
    Marco

  • #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..
    Marco

    Comment

    Working...
    X