fatherazrael
fatherazrael

Reputation: 5987

EJB with @TransactionManagement(javax.ejb.TransactionManagementType.BEAN) : Only session and message-driven beans allowed to access UserTransaction

Getting exception when i have already supplied: @TransactionManagement(javax.ejb.TransactionManagementType.BEAN)

Kindly help in fixing error

insertNewRecord:java.lang.IllegalStateException: WFLYEJB0137: Only session and message-driven beans with bean-managed transaction demarcation are allowed to access UserTransaction

Scheduler:

@Startup
@Singleton
@AccessTimeout(value = 30, unit = TimeUnit.MINUTES)
public class SnowPollerNew {

   @EJB
    Scrutiny scrutiny;

   @Schedule(hour = "*", minute = "*/1", persistent = false)
    @TransactionTimeout(value = 2, unit = TimeUnit.HOURS)
    public v

oid runTriggerFetchComputers() {
        File trigFileSNOWApplications = new File(TRIGFILE_DIR + TRIGFILE_COMPUTERS);
        if (trigFileSNOWApplications.exists()) {


            JobStatus jobStatus = scrutiny.insertNewRecord(JobName.COMPUTERS);

Scrutiny:

@Stateless

public class Scrutiny {
    private static final Logger log = Logger.getLogger(Scrutiny.class.getName());

    public Scrutiny() {
        System.out.println("Scrutiny");
    }

    @Inject
    StatusDao statusDao;

    public JobStatus insertNewRecord(JobName jName)  {

        JobStatus js = new JobStatus(jName, new Date());
        js.setStatus(Status.PROGRESS);
        try {
            statusDao.begin();
            statusDao.create(js);
            statusDao.flush();
            statusDao.commit();;

Job Impl:

@TransactionManagement(javax.ejb.TransactionManagementType.BEAN)
public class JobStatusDaoImpl extends GenericDaoImpl<JobStatus, String> implements StatusDao {
    private static final Logger LOG = Logger.getLogger(JobStatusDaoImpl.class.getName());

    @Override
    public List<JobStatus> checkExistingRecordToday(JobName jName) {
        LOG.info("checkExistingRecordToday:" + jName);
        return em.createNamedQuery("findByJobNameAndCurrentDate", JobStatus.class)
            .setParameter("jobName",jName).getResultList();
    }


}

Generic Dao Impl:

public abstract class GenericDaoImpl<T, PK> implements GenericDao<T, PK> {

    private static final Logger LOG = Logger.getLogger(GenericDaoImpl.class.getName());
    @PersistenceContext(unitName = "IntegratorMasterdataDS")
    protected EntityManager em;

    @Resource
    private SessionContext sessionContext;

   @Override
    public void begin() throws IllegalStateException, NotSupportedException, SystemException {
        sessionContext.getUserTransaction().begin();
    }

Upvotes: 0

Views: 675

Answers (0)

Related Questions