Scheduled Task - java.lang.reflect.InvocationTargetException

Hello guys,

I’ve created a Service Bean which basically “cancels old orders in my application”. This Bean is supposed to run regularly via the Scheduled Tasks.
It is working like a charm / no issues in my local application / studio deployed application.
In my live environment however it throws the following error. Has anyone seen this before, do i need to set some further configurations for my live environment?

image

This is how the scheduled task is setup:

image

This is the code of the Service:

package com.company.mediconn.service;

import com.company.mediconn.entity.*;
import com.haulmont.cuba.core.global.CommitContext;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.LoadContext;
import freemarker.template.utility.DateUtil;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

@Service(CleanUpService.NAME)
public class CleanUpServiceBean implements CleanUpService {

    @Inject
    private DataManager dataManager;

    @Override
    public void cancelOutdatedAuftragsanfragen() {
        LoadContext<Auftragsanfrage> loadContext = LoadContext.create(Auftragsanfrage.class)
                .setQuery(LoadContext.createQuery("select e from mediconn$Auftragsanfrage e where " +
                        "e.aaStatus = @enum(com.company.mediconn.entity.AaStatus.stat10) or " +
                        "e.aaStatus = @enum(com.company.mediconn.entity.AaStatus.stat20) or " +
                        "e.aaStatus = @enum(com.company.mediconn.entity.AaStatus.stat30) or " +
                        "e.aaStatus = @enum(com.company.mediconn.entity.AaStatus.stat35) "))
                        .setView("_cleanup");
        List<Auftragsanfrage> auftragsanfrageList = new ArrayList<>();
        auftragsanfrageList = dataManager.loadList(loadContext);

        Date latestEinsatzDate;
        Date minLatestEinsatzDate = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(minLatestEinsatzDate);
        c.add(Calendar.DATE, -7);
        minLatestEinsatzDate = c.getTime();

        for (Auftragsanfrage varAA : auftragsanfrageList) {
            latestEinsatzDate = null;
            for (AaEinsatz varEinsatz : varAA.getAaEinsatz()) {
                for (AaEinsatzZeitraum varEinsatzZeitraum : varEinsatz.getEinsatzZeitraum()) {
                    if (latestEinsatzDate != null) {
                        if (varEinsatzZeitraum.getAaZeitraum().getZeitraumBis().after(latestEinsatzDate)){
                            latestEinsatzDate = varEinsatzZeitraum.getAaZeitraum().getZeitraumBis();
                        }
                    } else {
                        latestEinsatzDate = varEinsatzZeitraum.getAaZeitraum().getZeitraumBis();
                    }
                }
            }


            if (latestEinsatzDate.before(minLatestEinsatzDate)) {
                if (varAA.getAaStatus().equals(AaStatus.stat35)) {
                    varAA.setAaStatus(AaStatus.stat83);
                } else {
                    varAA.setAaStatus(AaStatus.stat98);
                }
                CommitContext commitContext = new CommitContext();
                commitContext.addInstanceToCommit(varAA);
                dataManager.commit(commitContext);
            }

        }


    }

}

An this the code of the Bean:

package com.company.mediconn.service;

public interface CleanUpService {
    String NAME = "mediconn_CleanUpService";

    void cancelOutdatedAuftragsanfragen();
}

So nothing fancy. It runs without any issues locally in CUBA Studio. Only when deployed to the live / production environment it throws an error.

Does somebody have a hint for me?

Thanks
Daniel

Hi,
You need to look for the error message and stacktrace in the production server logs.
It is the only place that stores the reason of the problem.

1 Like

Hello Alex,

thanks very much for the help. I went through the logs again and indeed i found the exact error (in Line 57 of the code i’ve posted above) in the “catalina.out” log of the server.
I’ve seem to have missed that before.

Thanks
Daniel