You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Radhakrishna Kalyan <nr...@gmail.com> on 2014/11/01 21:22:36 UTC

Exception while running openejb application

Hi,

Yesterday we had deployed our application in our production for the first
time which was developed using OpenEJB standalone.
But we got an exception after a while when we tried to perform certain
operation.
Please find the attached exception file.

The application shall read certain data from a table(Invoice) in database
and create an entry in an another table (BatchOrder). After that it shall
create an xml message using that data
and send to a jms queue.
In the console log everything looks fine and the jms message has been sent.
In the console log the id of the newly created BatchOrder record is
printed, but at the end when we check the database no record has been
created in the table BatchOrder.

The classes involved are 3:
BatchManager
BatchOrderDao
OverdueBatchTimerService

Here is the following code snippet of my application.

---------------------------------------------------------------------------------------------------------------------------
@Stateless
public class BatchManager{
    @EJB
    private BatchOrderDao batchOrderDao;

    @Asynchronous
    @Lock(LockType.READ)
    public void createBatchMessage(...){
        ...Some code to read Invoice table...

        batchOrderDao.create(batchOrder);

        ...Some more code to send jms message...

    }
}

---------------------------------------------------------------------------------------------------------------------------
@Stateless
public class BatchOrderDao{

    @PersistenceContext(unitName = "datasource")
    private EntityManager entityManager;

    public void create(BatchOrder entity){
        entityManager.persist(entity);
        entityManager.flush();
    }

    @SuppressWarnings("unchecked")
    public List<Long> findBatchesWithOverdueReceipts(final Date date) {
        final Criteria criteria =
getSession().createCriteria(BatchOrder.class);

criteria.setProjection(Projections.distinct(Projections.property("iId")));
        criteria.add(Restrictions.isNull("iAlarmed"));
        ....Some more Restrictions.....
        return criteria.list();
    }

}

---------------------------------------------------------------------------------------------------------------------------
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "BATCH_ORDER")
public class BatchOrder {
  private static final long serialVersionUID = 1L;

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
allocationSize = 1)
  @Column(name = "BO_ID", unique = true, nullable = false, updatable =
false)
  private Long iId;

  @Column(name = "BO_ALARMED", unique = false, nullable = true, updatable =
true)
  private Date iAlarmed;

  .... Some more fields....

}
---------------------------------------------------------------------------------------------------------------------------
@Singleton
@Startup
@Lock(LockType.READ)
private class OverdueBatchTimerService{
    @Inject
    private BatchOrderDao dao;
    @Resource
    private TimerService timerService;
    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l * 1000l;

    @PostConstruct
    public void initialize() throws Exception {
        timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
TimerConfig());
    }

    @Timeout
    public void onTimeout(final Timer timer) {
        try{
            .. Some Code....
            dao.findBatchesWithOverdueReceipts(time);
            .... Some more code....
        } catch (final Exception ignore) {
            LOG.error("Some exception occured while excecuting onTimeout,
but IGNORED.", ignore);
        } finally {
            timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
new TimerConfig());
        }
    }
}
---------------------------------------------------------------------------------------------------------------------------

Please let me know if I am making any mistake.


-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 2 nov. 2014 20:53, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :
>
> Hi,
>
> We don't know if the issue was with hibernate and some kind of
> configuration.
> One thing I can say that I had an annotation in the BatchOrder class.
>
> @Entity
> @Cacheable
> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> @Table(name = "BATCH_ORDER")
> public class BatchOrder extends BaseEntity {
>
> }
>
> However we didn't able to reproduce the same on our QA. I will try this
> week on our Acceptence and see if we can able to reproduce the exception.
>
> But if not then at the end I will stick with the UserTransaction and see
> how it will work on prod.
>

It calls the same code on tomee side.
Try to stress a bit the server, can help to reproduce

> Kalyan
>
>
>
>
> On Sun, Nov 2, 2014 at 9:26 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > Le 2 nov. 2014 20:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
écrit
> > :
> > >
> > > Hi,
> > >
> > > I hope you are talking about the missing userTransaction.rollback();
> > inside
> > > the catch(Throwable ignore) block.
> >
> > Yes mainly, just ensure the transaction is finished
> >
> > > The code for sending of jms message can be moved out of the try block.
> > > Because it is ok to get any exception while sending the jms message
and
> > > still the database batchorder entity shall be created in the database.
> > >
> > > By the way we didn't had any jms rollback occured that day, because
the
> > jms
> > > message was consumed properly by the other jms queue consumer
> > application.
> > >
> >
> > Then can be a hibernate config issue no?
> >
> > > Kalyan
> > >
> > >
> > > On Sun, Nov 2, 2014 at 7:32 PM, Romain Manni-Bucau <
> > rmannibucau@gmail.com>
> > > wrote:
> > >
> > > > If you forget tge rollback your tx state will be broken and you ll
> > > > potentially get more issues.
> > > >
> > > > Can be linked to jms, no jms rollback? Maybe add more logs (activemq
> > ones)
> > > > Hi,
> > > >
> > > > Anyway after a while of reading and browsing I came to the following
> > > > conclusion. I have rewritten my BatchManager class to use
> > > > @TransactionManagement(TransactionManagementType.BEAN).
> > > >
> > > >
> > > > @Stateless
> > > > *@TransactionManagement(TransactionManagementType.BEAN)   *
> > > > public class BatchManager{
> > > >     @EJB
> > > >     private BatchOrderDao batchOrderDao;
> > > >
> > > >     @Resource
> > > >     private UserTransaction userTransaction;
> > > >
> > > >     @Asynchronous
> > > >     @Lock(LockType.READ)
> > > >     public void createBatchMessage(...){
> > > >     try{
> > > >         *userTransaction.begin();*
> > > >         ...Some code to read Invoice table...
> > > >
> > > >         batchOrderDao.create(batchOrder);
> > > >         *userTransaction.commit();*
> > > >
> > > >         ...Some more code to send jms message...
> > > >      } catch (final Throwable ignore) {
> > > >         ignore.printStackTrace();
> > > >      }
> > > >
> > > >     }
> > > > }
> > > >
> > > > This way I can be sure if the usertransaction is commited then the
> > record
> > > > is created in the database and we can send jms message without any
> > problem.
> > > >
> > > > Please correct me if my approach is incorrect.
> > > >
> > > > Regards
> > > > Kalyan
> > > >
> > > >
> > > >
> > > >
> > > > On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <
> > nrkkalyan@gmail.com
> > >
> > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I am sorry, I am not clear, what do you mean by random execution
> > order.
> > > > > Our requirement is, we have 2 tasks :
> > > > >
> > > > > *Task1:* The @Asynchronous method,
BatchManager.createBatchMessage()
> > is
> > > > > triggered by a different application through a http rest request.
> > > > >            As I mentioned previously, the goal of this method is
to
> > > > create
> > > > > a BatchOrder entity in database and send jms message by reading
> > Invoices
> > > > > table, with all the invoices as xml to a different application.
The
> > > > reason
> > > > > to use @Asynchronous because the method can take 30-50 minutes to
> > > > complete
> > > > > and we don't the http request to wait so long.
> > > > >
> > > > > *Task2:* OverdueBatchTimerService is scheduled to run every 5
minutes
> > to
> > > > > find all the batchorders with certain criteria and send an email
if
> > the
> > > > > criteria matches.
> > > > >
> > > > > If you observe in both tasks the common is the BatchOrder table.
> > Task1 is
> > > > > inserting into that table and Task2 is selecting from that table.
> > > > >
> > > > > I believe that both tasks run in 2 different threads, so I am not
> > clear
> > > > > how can an exception caused in Task2 caused rollback of the
> > transaction
> > > > in
> > > > > Task1.
> > > > > Is it possible?
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <
> > > > rmannibucau@gmail.com>
> > > > > wrote:
> > > > >
> > > > >> I think async usage leadd to some random execution order. Ensure
it
> > is
> > > > not
> > > > >> random then it should work
> > > > >> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
> > > > >>
> > > > >> > Hi
> > > > >> >
> > > > >> > Thank you. Can you please elaborate what do you mean by
> > synchronously.
> > > > >> >
> > > > >> > Regards
> > > > >> > /Kalyan
> > > > >> > 0733312584
> > > > >> >
> > > > >> > PS: I am bad at spelling because I use mobile.
> > > > >> >
> > > > >> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <
> > rmannibucau@gmail.com>
> > > > >> > wrote:
> > > > >> > >
> > > > >> > > This is an app exception and surely a timing issue. Rewrite
the
> > app
> > > > >> > > synchronously it will work so i sadly think it is on your
side
> > > > >> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <
> > nrkkalyan@gmail.com>
> > a
> > > > >> > écrit :
> > > > >> > >
> > > > >> > >> Sorry
> > > > >> > >> Please find the exception at the following url
> > > > >> > >>
> > > > >> > >>
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> > > > >> > >>
> > > > >> > >>
> > > > >> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> > > > >> > rmannibucau@gmail.com
> > > > >> > >> wrote:
> > > > >> > >>
> > > > >> > >>> Hi
> > > > >> > >>>
> > > > >> > >>> I dont see any attached file, can you gist or pastebin it?
> > > > >> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <
> > nrkkalyan@gmail.com>
> > > > a
> > > > >> > >> écrit
> > > > >> > >>> :
> > > > >> > >>>
> > > > >> > >>>>
> > > > >> > >>>>
> > > > >> > >>>> Hi,
> > > > >> > >>>>
> > > > >> > >>>> Yesterday we had deployed our application in our
production
> > for
> > > > the
> > > > >> > >> first
> > > > >> > >>>> time which was developed using OpenEJB standalone.
> > > > >> > >>>> But we got an exception after a while when we tried to
> > perform
> > > > >> certain
> > > > >> > >>>> operation.
> > > > >> > >>>> Please find the attached exception file.
> > > > >> > >>>>
> > > > >> > >>>> The application shall read certain data from a
table(Invoice)
> > in
> > > > >> > >> database
> > > > >> > >>>> and create an entry in an another table (BatchOrder).
After
> > that
> > > > it
> > > > >> > >> shall
> > > > >> > >>>> create an xml message using that data
> > > > >> > >>>> and send to a jms queue.
> > > > >> > >>>> In the console log everything looks fine and the jms
message
> > has
> > > > >> been
> > > > >> > >>> sent.
> > > > >> > >>>> In the console log the id of the newly created BatchOrder
> > record
> > > > is
> > > > >> > >>>> printed, but at the end when we check the database no
record
> > has
> > > > >> been
> > > > >> > >>>> created in the table BatchOrder.
> > > > >> > >>>>
> > > > >> > >>>> The classes involved are 3:
> > > > >> > >>>> BatchManager
> > > > >> > >>>> BatchOrderDao
> > > > >> > >>>> OverdueBatchTimerService
> > > > >> > >>>>
> > > > >> > >>>> Here is the following code snippet of my application.
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > > > >> > >>>> @Stateless
> > > > >> > >>>> public class BatchManager{
> > > > >> > >>>>    @EJB
> > > > >> > >>>>    private BatchOrderDao batchOrderDao;
> > > > >> > >>>>
> > > > >> > >>>>    @Asynchronous
> > > > >> > >>>>    @Lock(LockType.READ)
> > > > >> > >>>>    public void createBatchMessage(...){
> > > > >> > >>>>        ...Some code to read Invoice table...
> > > > >> > >>>>
> > > > >> > >>>>        batchOrderDao.create(batchOrder);
> > > > >> > >>>>
> > > > >> > >>>>        ...Some more code to send jms message...
> > > > >> > >>>>
> > > > >> > >>>>    }
> > > > >> > >>>> }
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > > > >> > >>>> @Stateless
> > > > >> > >>>> public class BatchOrderDao{
> > > > >> > >>>>
> > > > >> > >>>>    @PersistenceContext(unitName = "datasource")
> > > > >> > >>>>    private EntityManager entityManager;
> > > > >> > >>>>
> > > > >> > >>>>    public void create(BatchOrder entity){
> > > > >> > >>>>        entityManager.persist(entity);
> > > > >> > >>>>        entityManager.flush();
> > > > >> > >>>>    }
> > > > >> > >>>>
> > > > >> > >>>>    @SuppressWarnings("unchecked")
> > > > >> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final
> > Date
> > > > >> date) {
> > > > >> > >>>>        final Criteria criteria =
> > > > >> > >>>> getSession().createCriteria(BatchOrder.class);
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> >
criteria.setProjection(Projections.distinct(Projections.property("iId")));
> > > > >> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> > > > >> > >>>>        ....Some more Restrictions.....
> > > > >> > >>>>        return criteria.list();
> > > > >> > >>>>    }
> > > > >> > >>>>
> > > > >> > >>>> }
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > > > >> > >>>> @Entity
> > > > >> > >>>> @Cacheable
> > > > >> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > > > >> > >>>> @Table(name = "BATCH_ORDER")
> > > > >> > >>>> public class BatchOrder {
> > > > >> > >>>>  private static final long serialVersionUID = 1L;
> > > > >> > >>>>
> > > > >> > >>>>  @Id
> > > > >> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE,
> > generator =
> > > > >> > >>> "IdSeq")
> > > > >> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName =
> > "BOID_SEQ",
> > > > >> > >>>> allocationSize = 1)
> > > > >> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
> > > > >> updatable =
> > > > >> > >>>> false)
> > > > >> > >>>>  private Long iId;
> > > > >> > >>>>
> > > > >> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable =
> > true,
> > > > >> > >> updatable
> > > > >> > >>>> = true)
> > > > >> > >>>>  private Date iAlarmed;
> > > > >> > >>>>
> > > > >> > >>>>  .... Some more fields....
> > > > >> > >>>>
> > > > >> > >>>> }
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > > > >> > >>>> @Singleton
> > > > >> > >>>> @Startup
> > > > >> > >>>> @Lock(LockType.READ)
> > > > >> > >>>> private class OverdueBatchTimerService{
> > > > >> > >>>>    @Inject
> > > > >> > >>>>    private BatchOrderDao dao;
> > > > >> > >>>>    @Resource
> > > > >> > >>>>    private TimerService timerService;
> > > > >> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS =
5l *
> > 60l
> > > > *
> > > > >> > >>> 1000l;
> > > > >> > >>>>
> > > > >> > >>>>    @PostConstruct
> > > > >> > >>>>    public void initialize() throws Exception {
> > > > >> > >>>>
> > > > >> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > > > >> > >>>> new TimerConfig());
> > > > >> > >>>>    }
> > > > >> > >>>>
> > > > >> > >>>>    @Timeout
> > > > >> > >>>>    public void onTimeout(final Timer timer) {
> > > > >> > >>>>        try{
> > > > >> > >>>>            .. Some Code....
> > > > >> > >>>>            dao.findBatchesWithOverdueReceipts(time);
> > > > >> > >>>>            .... Some more code....
> > > > >> > >>>>        } catch (final Exception ignore) {
> > > > >> > >>>>            LOG.error("Some exception occured while
excecuting
> > > > >> > >> onTimeout,
> > > > >> > >>>> but IGNORED.", ignore);
> > > > >> > >>>>        } finally {
> > > > >> > >>>>
> > > > >> > >>>>
> > timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > > > new
> > > > >> > >>>> TimerConfig());
> > > > >> > >>>>        }
> > > > >> > >>>>    }
> > > > >> > >>>> }
> > > > >> > >>
> > > > >> >
> > > > >>
> > > >
> > > >
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > > > >> > >>>>
> > > > >> > >>>> Please let me know if I am making any mistake.
> > > > >> > >>>>
> > > > >> > >>>>
> > > > >> > >>>> --
> > > > >> > >>>> Thanks and Regards
> > > > >> > >>>> N Radhakrishna Kalyan
> > > > >> > >>>>
> > > > >> > >>>> P:  +46 733 312 584
> > > > >> > >>>> http://about.me/nrkkalyan
> > > > >> > >>>> <http://about.me/nrkkalyan>
> > > > >> > >>
> > > > >> > >>
> > > > >> > >>
> > > > >> > >> --
> > > > >> > >> Thanks and Regards
> > > > >> > >> N Radhakrishna Kalyan
> > > > >> > >>
> > > > >> > >> P:  +46 733 312 584
> > > > >> > >> http://about.me/nrkkalyan
> > > > >> > >> <http://about.me/nrkkalyan>
> > > > >> > >>
> > > > >> >
> > > > >>
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Thanks and Regards
> > > > > N Radhakrishna Kalyan
> > > > >
> > > > > P:  +46 733 312 584
> > > > > http://about.me/nrkkalyan
> > > > > <http://about.me/nrkkalyan>
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Thanks and Regards
> > > > N Radhakrishna Kalyan
> > > >
> > > > P:  +46 733 312 584
> > > > http://about.me/nrkkalyan
> > > > <http://about.me/nrkkalyan>
> > > >
> > >
> > >
> > >
> > > --
> > > Thanks and Regards
> > > N Radhakrishna Kalyan
> > >
> > > P:  +46 733 312 584
> > > http://about.me/nrkkalyan
> > > <http://about.me/nrkkalyan>
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Hi,

We don't know if the issue was with hibernate and some kind of
configuration.
One thing I can say that I had an annotation in the BatchOrder class.

@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "BATCH_ORDER")
public class BatchOrder extends BaseEntity {

}

However we didn't able to reproduce the same on our QA. I will try this
week on our Acceptence and see if we can able to reproduce the exception.

But if not then at the end I will stick with the UserTransaction and see
how it will work on prod.

Kalyan




On Sun, Nov 2, 2014 at 9:26 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Le 2 nov. 2014 20:23, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit
> :
> >
> > Hi,
> >
> > I hope you are talking about the missing userTransaction.rollback();
> inside
> > the catch(Throwable ignore) block.
>
> Yes mainly, just ensure the transaction is finished
>
> > The code for sending of jms message can be moved out of the try block.
> > Because it is ok to get any exception while sending the jms message and
> > still the database batchorder entity shall be created in the database.
> >
> > By the way we didn't had any jms rollback occured that day, because the
> jms
> > message was consumed properly by the other jms queue consumer
> application.
> >
>
> Then can be a hibernate config issue no?
>
> > Kalyan
> >
> >
> > On Sun, Nov 2, 2014 at 7:32 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> > > If you forget tge rollback your tx state will be broken and you ll
> > > potentially get more issues.
> > >
> > > Can be linked to jms, no jms rollback? Maybe add more logs (activemq
> ones)
> > > Hi,
> > >
> > > Anyway after a while of reading and browsing I came to the following
> > > conclusion. I have rewritten my BatchManager class to use
> > > @TransactionManagement(TransactionManagementType.BEAN).
> > >
> > >
> > > @Stateless
> > > *@TransactionManagement(TransactionManagementType.BEAN)   *
> > > public class BatchManager{
> > >     @EJB
> > >     private BatchOrderDao batchOrderDao;
> > >
> > >     @Resource
> > >     private UserTransaction userTransaction;
> > >
> > >     @Asynchronous
> > >     @Lock(LockType.READ)
> > >     public void createBatchMessage(...){
> > >     try{
> > >         *userTransaction.begin();*
> > >         ...Some code to read Invoice table...
> > >
> > >         batchOrderDao.create(batchOrder);
> > >         *userTransaction.commit();*
> > >
> > >         ...Some more code to send jms message...
> > >      } catch (final Throwable ignore) {
> > >         ignore.printStackTrace();
> > >      }
> > >
> > >     }
> > > }
> > >
> > > This way I can be sure if the usertransaction is commited then the
> record
> > > is created in the database and we can send jms message without any
> problem.
> > >
> > > Please correct me if my approach is incorrect.
> > >
> > > Regards
> > > Kalyan
> > >
> > >
> > >
> > >
> > > On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <
> nrkkalyan@gmail.com
> >
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > I am sorry, I am not clear, what do you mean by random execution
> order.
> > > > Our requirement is, we have 2 tasks :
> > > >
> > > > *Task1:* The @Asynchronous method, BatchManager.createBatchMessage()
> is
> > > > triggered by a different application through a http rest request.
> > > >            As I mentioned previously, the goal of this method is to
> > > create
> > > > a BatchOrder entity in database and send jms message by reading
> Invoices
> > > > table, with all the invoices as xml to a different application. The
> > > reason
> > > > to use @Asynchronous because the method can take 30-50 minutes to
> > > complete
> > > > and we don't the http request to wait so long.
> > > >
> > > > *Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes
> to
> > > > find all the batchorders with certain criteria and send an email if
> the
> > > > criteria matches.
> > > >
> > > > If you observe in both tasks the common is the BatchOrder table.
> Task1 is
> > > > inserting into that table and Task2 is selecting from that table.
> > > >
> > > > I believe that both tasks run in 2 different threads, so I am not
> clear
> > > > how can an exception caused in Task2 caused rollback of the
> transaction
> > > in
> > > > Task1.
> > > > Is it possible?
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <
> > > rmannibucau@gmail.com>
> > > > wrote:
> > > >
> > > >> I think async usage leadd to some random execution order. Ensure it
> is
> > > not
> > > >> random then it should work
> > > >> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
> > > >>
> > > >> > Hi
> > > >> >
> > > >> > Thank you. Can you please elaborate what do you mean by
> synchronously.
> > > >> >
> > > >> > Regards
> > > >> > /Kalyan
> > > >> > 0733312584
> > > >> >
> > > >> > PS: I am bad at spelling because I use mobile.
> > > >> >
> > > >> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > > >> > wrote:
> > > >> > >
> > > >> > > This is an app exception and surely a timing issue. Rewrite the
> app
> > > >> > > synchronously it will work so i sadly think it is on your side
> > > >> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <
> nrkkalyan@gmail.com>
> a
> > > >> > écrit :
> > > >> > >
> > > >> > >> Sorry
> > > >> > >> Please find the exception at the following url
> > > >> > >>
> > > >> > >>
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> > > >> > >>
> > > >> > >>
> > > >> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> > > >> > rmannibucau@gmail.com
> > > >> > >> wrote:
> > > >> > >>
> > > >> > >>> Hi
> > > >> > >>>
> > > >> > >>> I dont see any attached file, can you gist or pastebin it?
> > > >> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <
> nrkkalyan@gmail.com>
> > > a
> > > >> > >> écrit
> > > >> > >>> :
> > > >> > >>>
> > > >> > >>>>
> > > >> > >>>>
> > > >> > >>>> Hi,
> > > >> > >>>>
> > > >> > >>>> Yesterday we had deployed our application in our production
> for
> > > the
> > > >> > >> first
> > > >> > >>>> time which was developed using OpenEJB standalone.
> > > >> > >>>> But we got an exception after a while when we tried to
> perform
> > > >> certain
> > > >> > >>>> operation.
> > > >> > >>>> Please find the attached exception file.
> > > >> > >>>>
> > > >> > >>>> The application shall read certain data from a table(Invoice)
> in
> > > >> > >> database
> > > >> > >>>> and create an entry in an another table (BatchOrder). After
> that
> > > it
> > > >> > >> shall
> > > >> > >>>> create an xml message using that data
> > > >> > >>>> and send to a jms queue.
> > > >> > >>>> In the console log everything looks fine and the jms message
> has
> > > >> been
> > > >> > >>> sent.
> > > >> > >>>> In the console log the id of the newly created BatchOrder
> record
> > > is
> > > >> > >>>> printed, but at the end when we check the database no record
> has
> > > >> been
> > > >> > >>>> created in the table BatchOrder.
> > > >> > >>>>
> > > >> > >>>> The classes involved are 3:
> > > >> > >>>> BatchManager
> > > >> > >>>> BatchOrderDao
> > > >> > >>>> OverdueBatchTimerService
> > > >> > >>>>
> > > >> > >>>> Here is the following code snippet of my application.
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> ---------------------------------------------------------------------------------------------------------------------------
> > > >> > >>>> @Stateless
> > > >> > >>>> public class BatchManager{
> > > >> > >>>>    @EJB
> > > >> > >>>>    private BatchOrderDao batchOrderDao;
> > > >> > >>>>
> > > >> > >>>>    @Asynchronous
> > > >> > >>>>    @Lock(LockType.READ)
> > > >> > >>>>    public void createBatchMessage(...){
> > > >> > >>>>        ...Some code to read Invoice table...
> > > >> > >>>>
> > > >> > >>>>        batchOrderDao.create(batchOrder);
> > > >> > >>>>
> > > >> > >>>>        ...Some more code to send jms message...
> > > >> > >>>>
> > > >> > >>>>    }
> > > >> > >>>> }
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> ---------------------------------------------------------------------------------------------------------------------------
> > > >> > >>>> @Stateless
> > > >> > >>>> public class BatchOrderDao{
> > > >> > >>>>
> > > >> > >>>>    @PersistenceContext(unitName = "datasource")
> > > >> > >>>>    private EntityManager entityManager;
> > > >> > >>>>
> > > >> > >>>>    public void create(BatchOrder entity){
> > > >> > >>>>        entityManager.persist(entity);
> > > >> > >>>>        entityManager.flush();
> > > >> > >>>>    }
> > > >> > >>>>
> > > >> > >>>>    @SuppressWarnings("unchecked")
> > > >> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final
> Date
> > > >> date) {
> > > >> > >>>>        final Criteria criteria =
> > > >> > >>>> getSession().createCriteria(BatchOrder.class);
> > > >> > >>
> > > >> >
> > > >>
> > >
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> > > >> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> > > >> > >>>>        ....Some more Restrictions.....
> > > >> > >>>>        return criteria.list();
> > > >> > >>>>    }
> > > >> > >>>>
> > > >> > >>>> }
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> ---------------------------------------------------------------------------------------------------------------------------
> > > >> > >>>> @Entity
> > > >> > >>>> @Cacheable
> > > >> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > > >> > >>>> @Table(name = "BATCH_ORDER")
> > > >> > >>>> public class BatchOrder {
> > > >> > >>>>  private static final long serialVersionUID = 1L;
> > > >> > >>>>
> > > >> > >>>>  @Id
> > > >> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE,
> generator =
> > > >> > >>> "IdSeq")
> > > >> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName =
> "BOID_SEQ",
> > > >> > >>>> allocationSize = 1)
> > > >> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
> > > >> updatable =
> > > >> > >>>> false)
> > > >> > >>>>  private Long iId;
> > > >> > >>>>
> > > >> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable =
> true,
> > > >> > >> updatable
> > > >> > >>>> = true)
> > > >> > >>>>  private Date iAlarmed;
> > > >> > >>>>
> > > >> > >>>>  .... Some more fields....
> > > >> > >>>>
> > > >> > >>>> }
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> ---------------------------------------------------------------------------------------------------------------------------
> > > >> > >>>> @Singleton
> > > >> > >>>> @Startup
> > > >> > >>>> @Lock(LockType.READ)
> > > >> > >>>> private class OverdueBatchTimerService{
> > > >> > >>>>    @Inject
> > > >> > >>>>    private BatchOrderDao dao;
> > > >> > >>>>    @Resource
> > > >> > >>>>    private TimerService timerService;
> > > >> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l *
> 60l
> > > *
> > > >> > >>> 1000l;
> > > >> > >>>>
> > > >> > >>>>    @PostConstruct
> > > >> > >>>>    public void initialize() throws Exception {
> > > >> > >>>>
> > > >> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > > >> > >>>> new TimerConfig());
> > > >> > >>>>    }
> > > >> > >>>>
> > > >> > >>>>    @Timeout
> > > >> > >>>>    public void onTimeout(final Timer timer) {
> > > >> > >>>>        try{
> > > >> > >>>>            .. Some Code....
> > > >> > >>>>            dao.findBatchesWithOverdueReceipts(time);
> > > >> > >>>>            .... Some more code....
> > > >> > >>>>        } catch (final Exception ignore) {
> > > >> > >>>>            LOG.error("Some exception occured while excecuting
> > > >> > >> onTimeout,
> > > >> > >>>> but IGNORED.", ignore);
> > > >> > >>>>        } finally {
> > > >> > >>>>
> > > >> > >>>>
> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > > new
> > > >> > >>>> TimerConfig());
> > > >> > >>>>        }
> > > >> > >>>>    }
> > > >> > >>>> }
> > > >> > >>
> > > >> >
> > > >>
> > >
> > >
>
> ---------------------------------------------------------------------------------------------------------------------------
> > > >> > >>>>
> > > >> > >>>> Please let me know if I am making any mistake.
> > > >> > >>>>
> > > >> > >>>>
> > > >> > >>>> --
> > > >> > >>>> Thanks and Regards
> > > >> > >>>> N Radhakrishna Kalyan
> > > >> > >>>>
> > > >> > >>>> P:  +46 733 312 584
> > > >> > >>>> http://about.me/nrkkalyan
> > > >> > >>>> <http://about.me/nrkkalyan>
> > > >> > >>
> > > >> > >>
> > > >> > >>
> > > >> > >> --
> > > >> > >> Thanks and Regards
> > > >> > >> N Radhakrishna Kalyan
> > > >> > >>
> > > >> > >> P:  +46 733 312 584
> > > >> > >> http://about.me/nrkkalyan
> > > >> > >> <http://about.me/nrkkalyan>
> > > >> > >>
> > > >> >
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > Thanks and Regards
> > > > N Radhakrishna Kalyan
> > > >
> > > > P:  +46 733 312 584
> > > > http://about.me/nrkkalyan
> > > > <http://about.me/nrkkalyan>
> > > >
> > >
> > >
> > >
> > > --
> > > Thanks and Regards
> > > N Radhakrishna Kalyan
> > >
> > > P:  +46 733 312 584
> > > http://about.me/nrkkalyan
> > > <http://about.me/nrkkalyan>
> > >
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Le 2 nov. 2014 20:23, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :
>
> Hi,
>
> I hope you are talking about the missing userTransaction.rollback();
inside
> the catch(Throwable ignore) block.

Yes mainly, just ensure the transaction is finished

> The code for sending of jms message can be moved out of the try block.
> Because it is ok to get any exception while sending the jms message and
> still the database batchorder entity shall be created in the database.
>
> By the way we didn't had any jms rollback occured that day, because the
jms
> message was consumed properly by the other jms queue consumer application.
>

Then can be a hibernate config issue no?

> Kalyan
>
>
> On Sun, Nov 2, 2014 at 7:32 PM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > If you forget tge rollback your tx state will be broken and you ll
> > potentially get more issues.
> >
> > Can be linked to jms, no jms rollback? Maybe add more logs (activemq
ones)
> > Hi,
> >
> > Anyway after a while of reading and browsing I came to the following
> > conclusion. I have rewritten my BatchManager class to use
> > @TransactionManagement(TransactionManagementType.BEAN).
> >
> >
> > @Stateless
> > *@TransactionManagement(TransactionManagementType.BEAN)   *
> > public class BatchManager{
> >     @EJB
> >     private BatchOrderDao batchOrderDao;
> >
> >     @Resource
> >     private UserTransaction userTransaction;
> >
> >     @Asynchronous
> >     @Lock(LockType.READ)
> >     public void createBatchMessage(...){
> >     try{
> >         *userTransaction.begin();*
> >         ...Some code to read Invoice table...
> >
> >         batchOrderDao.create(batchOrder);
> >         *userTransaction.commit();*
> >
> >         ...Some more code to send jms message...
> >      } catch (final Throwable ignore) {
> >         ignore.printStackTrace();
> >      }
> >
> >     }
> > }
> >
> > This way I can be sure if the usertransaction is commited then the
record
> > is created in the database and we can send jms message without any
problem.
> >
> > Please correct me if my approach is incorrect.
> >
> > Regards
> > Kalyan
> >
> >
> >
> >
> > On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <nrkkalyan@gmail.com
>
> > wrote:
> >
> > > Hi,
> > >
> > > I am sorry, I am not clear, what do you mean by random execution
order.
> > > Our requirement is, we have 2 tasks :
> > >
> > > *Task1:* The @Asynchronous method, BatchManager.createBatchMessage()
is
> > > triggered by a different application through a http rest request.
> > >            As I mentioned previously, the goal of this method is to
> > create
> > > a BatchOrder entity in database and send jms message by reading
Invoices
> > > table, with all the invoices as xml to a different application. The
> > reason
> > > to use @Asynchronous because the method can take 30-50 minutes to
> > complete
> > > and we don't the http request to wait so long.
> > >
> > > *Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes
to
> > > find all the batchorders with certain criteria and send an email if
the
> > > criteria matches.
> > >
> > > If you observe in both tasks the common is the BatchOrder table.
Task1 is
> > > inserting into that table and Task2 is selecting from that table.
> > >
> > > I believe that both tasks run in 2 different threads, so I am not
clear
> > > how can an exception caused in Task2 caused rollback of the
transaction
> > in
> > > Task1.
> > > Is it possible?
> > >
> > >
> > >
> > >
> > >
> > > On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <
> > rmannibucau@gmail.com>
> > > wrote:
> > >
> > >> I think async usage leadd to some random execution order. Ensure it
is
> > not
> > >> random then it should work
> > >> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
> > >>
> > >> > Hi
> > >> >
> > >> > Thank you. Can you please elaborate what do you mean by
synchronously.
> > >> >
> > >> > Regards
> > >> > /Kalyan
> > >> > 0733312584
> > >> >
> > >> > PS: I am bad at spelling because I use mobile.
> > >> >
> > >> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <
rmannibucau@gmail.com>
> > >> > wrote:
> > >> > >
> > >> > > This is an app exception and surely a timing issue. Rewrite the
app
> > >> > > synchronously it will work so i sadly think it is on your side
> > >> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com>
a
> > >> > écrit :
> > >> > >
> > >> > >> Sorry
> > >> > >> Please find the exception at the following url
> > >> > >>
> > >> > >>
> > >> > >>
> > >> >
> > >>
> >
> >
https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> > >> > >>
> > >> > >>
> > >> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> > >> > rmannibucau@gmail.com
> > >> > >> wrote:
> > >> > >>
> > >> > >>> Hi
> > >> > >>>
> > >> > >>> I dont see any attached file, can you gist or pastebin it?
> > >> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <
nrkkalyan@gmail.com>
> > a
> > >> > >> écrit
> > >> > >>> :
> > >> > >>>
> > >> > >>>>
> > >> > >>>>
> > >> > >>>> Hi,
> > >> > >>>>
> > >> > >>>> Yesterday we had deployed our application in our production
for
> > the
> > >> > >> first
> > >> > >>>> time which was developed using OpenEJB standalone.
> > >> > >>>> But we got an exception after a while when we tried to perform
> > >> certain
> > >> > >>>> operation.
> > >> > >>>> Please find the attached exception file.
> > >> > >>>>
> > >> > >>>> The application shall read certain data from a table(Invoice)
in
> > >> > >> database
> > >> > >>>> and create an entry in an another table (BatchOrder). After
that
> > it
> > >> > >> shall
> > >> > >>>> create an xml message using that data
> > >> > >>>> and send to a jms queue.
> > >> > >>>> In the console log everything looks fine and the jms message
has
> > >> been
> > >> > >>> sent.
> > >> > >>>> In the console log the id of the newly created BatchOrder
record
> > is
> > >> > >>>> printed, but at the end when we check the database no record
has
> > >> been
> > >> > >>>> created in the table BatchOrder.
> > >> > >>>>
> > >> > >>>> The classes involved are 3:
> > >> > >>>> BatchManager
> > >> > >>>> BatchOrderDao
> > >> > >>>> OverdueBatchTimerService
> > >> > >>>>
> > >> > >>>> Here is the following code snippet of my application.
> > >> > >>
> > >> >
> > >>
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > >> > >>>> @Stateless
> > >> > >>>> public class BatchManager{
> > >> > >>>>    @EJB
> > >> > >>>>    private BatchOrderDao batchOrderDao;
> > >> > >>>>
> > >> > >>>>    @Asynchronous
> > >> > >>>>    @Lock(LockType.READ)
> > >> > >>>>    public void createBatchMessage(...){
> > >> > >>>>        ...Some code to read Invoice table...
> > >> > >>>>
> > >> > >>>>        batchOrderDao.create(batchOrder);
> > >> > >>>>
> > >> > >>>>        ...Some more code to send jms message...
> > >> > >>>>
> > >> > >>>>    }
> > >> > >>>> }
> > >> > >>
> > >> >
> > >>
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > >> > >>>> @Stateless
> > >> > >>>> public class BatchOrderDao{
> > >> > >>>>
> > >> > >>>>    @PersistenceContext(unitName = "datasource")
> > >> > >>>>    private EntityManager entityManager;
> > >> > >>>>
> > >> > >>>>    public void create(BatchOrder entity){
> > >> > >>>>        entityManager.persist(entity);
> > >> > >>>>        entityManager.flush();
> > >> > >>>>    }
> > >> > >>>>
> > >> > >>>>    @SuppressWarnings("unchecked")
> > >> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date
> > >> date) {
> > >> > >>>>        final Criteria criteria =
> > >> > >>>> getSession().createCriteria(BatchOrder.class);
> > >> > >>
> > >> >
> > >>
> >
criteria.setProjection(Projections.distinct(Projections.property("iId")));
> > >> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> > >> > >>>>        ....Some more Restrictions.....
> > >> > >>>>        return criteria.list();
> > >> > >>>>    }
> > >> > >>>>
> > >> > >>>> }
> > >> > >>
> > >> >
> > >>
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > >> > >>>> @Entity
> > >> > >>>> @Cacheable
> > >> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > >> > >>>> @Table(name = "BATCH_ORDER")
> > >> > >>>> public class BatchOrder {
> > >> > >>>>  private static final long serialVersionUID = 1L;
> > >> > >>>>
> > >> > >>>>  @Id
> > >> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE,
generator =
> > >> > >>> "IdSeq")
> > >> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> > >> > >>>> allocationSize = 1)
> > >> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
> > >> updatable =
> > >> > >>>> false)
> > >> > >>>>  private Long iId;
> > >> > >>>>
> > >> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
> > >> > >> updatable
> > >> > >>>> = true)
> > >> > >>>>  private Date iAlarmed;
> > >> > >>>>
> > >> > >>>>  .... Some more fields....
> > >> > >>>>
> > >> > >>>> }
> > >> > >>
> > >> >
> > >>
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > >> > >>>> @Singleton
> > >> > >>>> @Startup
> > >> > >>>> @Lock(LockType.READ)
> > >> > >>>> private class OverdueBatchTimerService{
> > >> > >>>>    @Inject
> > >> > >>>>    private BatchOrderDao dao;
> > >> > >>>>    @Resource
> > >> > >>>>    private TimerService timerService;
> > >> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l *
60l
> > *
> > >> > >>> 1000l;
> > >> > >>>>
> > >> > >>>>    @PostConstruct
> > >> > >>>>    public void initialize() throws Exception {
> > >> > >>>>
> > >> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > >> > >>>> new TimerConfig());
> > >> > >>>>    }
> > >> > >>>>
> > >> > >>>>    @Timeout
> > >> > >>>>    public void onTimeout(final Timer timer) {
> > >> > >>>>        try{
> > >> > >>>>            .. Some Code....
> > >> > >>>>            dao.findBatchesWithOverdueReceipts(time);
> > >> > >>>>            .... Some more code....
> > >> > >>>>        } catch (final Exception ignore) {
> > >> > >>>>            LOG.error("Some exception occured while excecuting
> > >> > >> onTimeout,
> > >> > >>>> but IGNORED.", ignore);
> > >> > >>>>        } finally {
> > >> > >>>>
> > >> > >>>>
timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > new
> > >> > >>>> TimerConfig());
> > >> > >>>>        }
> > >> > >>>>    }
> > >> > >>>> }
> > >> > >>
> > >> >
> > >>
> >
> >
---------------------------------------------------------------------------------------------------------------------------
> > >> > >>>>
> > >> > >>>> Please let me know if I am making any mistake.
> > >> > >>>>
> > >> > >>>>
> > >> > >>>> --
> > >> > >>>> Thanks and Regards
> > >> > >>>> N Radhakrishna Kalyan
> > >> > >>>>
> > >> > >>>> P:  +46 733 312 584
> > >> > >>>> http://about.me/nrkkalyan
> > >> > >>>> <http://about.me/nrkkalyan>
> > >> > >>
> > >> > >>
> > >> > >>
> > >> > >> --
> > >> > >> Thanks and Regards
> > >> > >> N Radhakrishna Kalyan
> > >> > >>
> > >> > >> P:  +46 733 312 584
> > >> > >> http://about.me/nrkkalyan
> > >> > >> <http://about.me/nrkkalyan>
> > >> > >>
> > >> >
> > >>
> > >
> > >
> > >
> > > --
> > > Thanks and Regards
> > > N Radhakrishna Kalyan
> > >
> > > P:  +46 733 312 584
> > > http://about.me/nrkkalyan
> > > <http://about.me/nrkkalyan>
> > >
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Hi,

I hope you are talking about the missing userTransaction.rollback(); inside
the catch(Throwable ignore) block.
The code for sending of jms message can be moved out of the try block.
Because it is ok to get any exception while sending the jms message and
still the database batchorder entity shall be created in the database.

By the way we didn't had any jms rollback occured that day, because the jms
message was consumed properly by the other jms queue consumer application.

Kalyan


On Sun, Nov 2, 2014 at 7:32 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> If you forget tge rollback your tx state will be broken and you ll
> potentially get more issues.
>
> Can be linked to jms, no jms rollback? Maybe add more logs (activemq ones)
> Hi,
>
> Anyway after a while of reading and browsing I came to the following
> conclusion. I have rewritten my BatchManager class to use
> @TransactionManagement(TransactionManagementType.BEAN).
>
>
> @Stateless
> *@TransactionManagement(TransactionManagementType.BEAN)   *
> public class BatchManager{
>     @EJB
>     private BatchOrderDao batchOrderDao;
>
>     @Resource
>     private UserTransaction userTransaction;
>
>     @Asynchronous
>     @Lock(LockType.READ)
>     public void createBatchMessage(...){
>     try{
>         *userTransaction.begin();*
>         ...Some code to read Invoice table...
>
>         batchOrderDao.create(batchOrder);
>         *userTransaction.commit();*
>
>         ...Some more code to send jms message...
>      } catch (final Throwable ignore) {
>         ignore.printStackTrace();
>      }
>
>     }
> }
>
> This way I can be sure if the usertransaction is commited then the record
> is created in the database and we can send jms message without any problem.
>
> Please correct me if my approach is incorrect.
>
> Regards
> Kalyan
>
>
>
>
> On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <nr...@gmail.com>
> wrote:
>
> > Hi,
> >
> > I am sorry, I am not clear, what do you mean by random execution order.
> > Our requirement is, we have 2 tasks :
> >
> > *Task1:* The @Asynchronous method, BatchManager.createBatchMessage() is
> > triggered by a different application through a http rest request.
> >            As I mentioned previously, the goal of this method is to
> create
> > a BatchOrder entity in database and send jms message by reading Invoices
> > table, with all the invoices as xml to a different application. The
> reason
> > to use @Asynchronous because the method can take 30-50 minutes to
> complete
> > and we don't the http request to wait so long.
> >
> > *Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes to
> > find all the batchorders with certain criteria and send an email if the
> > criteria matches.
> >
> > If you observe in both tasks the common is the BatchOrder table. Task1 is
> > inserting into that table and Task2 is selecting from that table.
> >
> > I believe that both tasks run in 2 different threads, so I am not clear
> > how can an exception caused in Task2 caused rollback of the transaction
> in
> > Task1.
> > Is it possible?
> >
> >
> >
> >
> >
> > On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com>
> > wrote:
> >
> >> I think async usage leadd to some random execution order. Ensure it is
> not
> >> random then it should work
> >> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
> >>
> >> > Hi
> >> >
> >> > Thank you. Can you please elaborate what do you mean by synchronously.
> >> >
> >> > Regards
> >> > /Kalyan
> >> > 0733312584
> >> >
> >> > PS: I am bad at spelling because I use mobile.
> >> >
> >> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com>
> >> > wrote:
> >> > >
> >> > > This is an app exception and surely a timing issue. Rewrite the app
> >> > > synchronously it will work so i sadly think it is on your side
> >> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a
> >> > écrit :
> >> > >
> >> > >> Sorry
> >> > >> Please find the exception at the following url
> >> > >>
> >> > >>
> >> > >>
> >> >
> >>
>
> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> >> > >>
> >> > >>
> >> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> >> > rmannibucau@gmail.com
> >> > >> wrote:
> >> > >>
> >> > >>> Hi
> >> > >>>
> >> > >>> I dont see any attached file, can you gist or pastebin it?
> >> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com>
> a
> >> > >> écrit
> >> > >>> :
> >> > >>>
> >> > >>>>
> >> > >>>>
> >> > >>>> Hi,
> >> > >>>>
> >> > >>>> Yesterday we had deployed our application in our production for
> the
> >> > >> first
> >> > >>>> time which was developed using OpenEJB standalone.
> >> > >>>> But we got an exception after a while when we tried to perform
> >> certain
> >> > >>>> operation.
> >> > >>>> Please find the attached exception file.
> >> > >>>>
> >> > >>>> The application shall read certain data from a table(Invoice) in
> >> > >> database
> >> > >>>> and create an entry in an another table (BatchOrder). After that
> it
> >> > >> shall
> >> > >>>> create an xml message using that data
> >> > >>>> and send to a jms queue.
> >> > >>>> In the console log everything looks fine and the jms message has
> >> been
> >> > >>> sent.
> >> > >>>> In the console log the id of the newly created BatchOrder record
> is
> >> > >>>> printed, but at the end when we check the database no record has
> >> been
> >> > >>>> created in the table BatchOrder.
> >> > >>>>
> >> > >>>> The classes involved are 3:
> >> > >>>> BatchManager
> >> > >>>> BatchOrderDao
> >> > >>>> OverdueBatchTimerService
> >> > >>>>
> >> > >>>> Here is the following code snippet of my application.
> >> > >>
> >> >
> >>
>
> ---------------------------------------------------------------------------------------------------------------------------
> >> > >>>> @Stateless
> >> > >>>> public class BatchManager{
> >> > >>>>    @EJB
> >> > >>>>    private BatchOrderDao batchOrderDao;
> >> > >>>>
> >> > >>>>    @Asynchronous
> >> > >>>>    @Lock(LockType.READ)
> >> > >>>>    public void createBatchMessage(...){
> >> > >>>>        ...Some code to read Invoice table...
> >> > >>>>
> >> > >>>>        batchOrderDao.create(batchOrder);
> >> > >>>>
> >> > >>>>        ...Some more code to send jms message...
> >> > >>>>
> >> > >>>>    }
> >> > >>>> }
> >> > >>
> >> >
> >>
>
> ---------------------------------------------------------------------------------------------------------------------------
> >> > >>>> @Stateless
> >> > >>>> public class BatchOrderDao{
> >> > >>>>
> >> > >>>>    @PersistenceContext(unitName = "datasource")
> >> > >>>>    private EntityManager entityManager;
> >> > >>>>
> >> > >>>>    public void create(BatchOrder entity){
> >> > >>>>        entityManager.persist(entity);
> >> > >>>>        entityManager.flush();
> >> > >>>>    }
> >> > >>>>
> >> > >>>>    @SuppressWarnings("unchecked")
> >> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date
> >> date) {
> >> > >>>>        final Criteria criteria =
> >> > >>>> getSession().createCriteria(BatchOrder.class);
> >> > >>
> >> >
> >>
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> >> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> >> > >>>>        ....Some more Restrictions.....
> >> > >>>>        return criteria.list();
> >> > >>>>    }
> >> > >>>>
> >> > >>>> }
> >> > >>
> >> >
> >>
>
> ---------------------------------------------------------------------------------------------------------------------------
> >> > >>>> @Entity
> >> > >>>> @Cacheable
> >> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> >> > >>>> @Table(name = "BATCH_ORDER")
> >> > >>>> public class BatchOrder {
> >> > >>>>  private static final long serialVersionUID = 1L;
> >> > >>>>
> >> > >>>>  @Id
> >> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> >> > >>> "IdSeq")
> >> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> >> > >>>> allocationSize = 1)
> >> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
> >> updatable =
> >> > >>>> false)
> >> > >>>>  private Long iId;
> >> > >>>>
> >> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
> >> > >> updatable
> >> > >>>> = true)
> >> > >>>>  private Date iAlarmed;
> >> > >>>>
> >> > >>>>  .... Some more fields....
> >> > >>>>
> >> > >>>> }
> >> > >>
> >> >
> >>
>
> ---------------------------------------------------------------------------------------------------------------------------
> >> > >>>> @Singleton
> >> > >>>> @Startup
> >> > >>>> @Lock(LockType.READ)
> >> > >>>> private class OverdueBatchTimerService{
> >> > >>>>    @Inject
> >> > >>>>    private BatchOrderDao dao;
> >> > >>>>    @Resource
> >> > >>>>    private TimerService timerService;
> >> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l
> *
> >> > >>> 1000l;
> >> > >>>>
> >> > >>>>    @PostConstruct
> >> > >>>>    public void initialize() throws Exception {
> >> > >>>>
> >> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> >> > >>>> new TimerConfig());
> >> > >>>>    }
> >> > >>>>
> >> > >>>>    @Timeout
> >> > >>>>    public void onTimeout(final Timer timer) {
> >> > >>>>        try{
> >> > >>>>            .. Some Code....
> >> > >>>>            dao.findBatchesWithOverdueReceipts(time);
> >> > >>>>            .... Some more code....
> >> > >>>>        } catch (final Exception ignore) {
> >> > >>>>            LOG.error("Some exception occured while excecuting
> >> > >> onTimeout,
> >> > >>>> but IGNORED.", ignore);
> >> > >>>>        } finally {
> >> > >>>>
> >> > >>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> new
> >> > >>>> TimerConfig());
> >> > >>>>        }
> >> > >>>>    }
> >> > >>>> }
> >> > >>
> >> >
> >>
>
> ---------------------------------------------------------------------------------------------------------------------------
> >> > >>>>
> >> > >>>> Please let me know if I am making any mistake.
> >> > >>>>
> >> > >>>>
> >> > >>>> --
> >> > >>>> Thanks and Regards
> >> > >>>> N Radhakrishna Kalyan
> >> > >>>>
> >> > >>>> P:  +46 733 312 584
> >> > >>>> http://about.me/nrkkalyan
> >> > >>>> <http://about.me/nrkkalyan>
> >> > >>
> >> > >>
> >> > >>
> >> > >> --
> >> > >> Thanks and Regards
> >> > >> N Radhakrishna Kalyan
> >> > >>
> >> > >> P:  +46 733 312 584
> >> > >> http://about.me/nrkkalyan
> >> > >> <http://about.me/nrkkalyan>
> >> > >>
> >> >
> >>
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
If you forget tge rollback your tx state will be broken and you ll
potentially get more issues.

Can be linked to jms, no jms rollback? Maybe add more logs (activemq ones)
Hi,

Anyway after a while of reading and browsing I came to the following
conclusion. I have rewritten my BatchManager class to use
@TransactionManagement(TransactionManagementType.BEAN).


@Stateless
*@TransactionManagement(TransactionManagementType.BEAN)   *
public class BatchManager{
    @EJB
    private BatchOrderDao batchOrderDao;

    @Resource
    private UserTransaction userTransaction;

    @Asynchronous
    @Lock(LockType.READ)
    public void createBatchMessage(...){
    try{
        *userTransaction.begin();*
        ...Some code to read Invoice table...

        batchOrderDao.create(batchOrder);
        *userTransaction.commit();*

        ...Some more code to send jms message...
     } catch (final Throwable ignore) {
        ignore.printStackTrace();
     }

    }
}

This way I can be sure if the usertransaction is commited then the record
is created in the database and we can send jms message without any problem.

Please correct me if my approach is incorrect.

Regards
Kalyan




On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <nr...@gmail.com>
wrote:

> Hi,
>
> I am sorry, I am not clear, what do you mean by random execution order.
> Our requirement is, we have 2 tasks :
>
> *Task1:* The @Asynchronous method, BatchManager.createBatchMessage() is
> triggered by a different application through a http rest request.
>            As I mentioned previously, the goal of this method is to create
> a BatchOrder entity in database and send jms message by reading Invoices
> table, with all the invoices as xml to a different application. The reason
> to use @Asynchronous because the method can take 30-50 minutes to complete
> and we don't the http request to wait so long.
>
> *Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes to
> find all the batchorders with certain criteria and send an email if the
> criteria matches.
>
> If you observe in both tasks the common is the BatchOrder table. Task1 is
> inserting into that table and Task2 is selecting from that table.
>
> I believe that both tasks run in 2 different threads, so I am not clear
> how can an exception caused in Task2 caused rollback of the transaction in
> Task1.
> Is it possible?
>
>
>
>
>
> On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
>> I think async usage leadd to some random execution order. Ensure it is
not
>> random then it should work
>> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
>>
>> > Hi
>> >
>> > Thank you. Can you please elaborate what do you mean by synchronously.
>> >
>> > Regards
>> > /Kalyan
>> > 0733312584
>> >
>> > PS: I am bad at spelling because I use mobile.
>> >
>> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com>
>> > wrote:
>> > >
>> > > This is an app exception and surely a timing issue. Rewrite the app
>> > > synchronously it will work so i sadly think it is on your side
>> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a
>> > écrit :
>> > >
>> > >> Sorry
>> > >> Please find the exception at the following url
>> > >>
>> > >>
>> > >>
>> >
>>
https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
>> > >>
>> > >>
>> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
>> > rmannibucau@gmail.com
>> > >> wrote:
>> > >>
>> > >>> Hi
>> > >>>
>> > >>> I dont see any attached file, can you gist or pastebin it?
>> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
>> > >> écrit
>> > >>> :
>> > >>>
>> > >>>>
>> > >>>>
>> > >>>> Hi,
>> > >>>>
>> > >>>> Yesterday we had deployed our application in our production for
the
>> > >> first
>> > >>>> time which was developed using OpenEJB standalone.
>> > >>>> But we got an exception after a while when we tried to perform
>> certain
>> > >>>> operation.
>> > >>>> Please find the attached exception file.
>> > >>>>
>> > >>>> The application shall read certain data from a table(Invoice) in
>> > >> database
>> > >>>> and create an entry in an another table (BatchOrder). After that
it
>> > >> shall
>> > >>>> create an xml message using that data
>> > >>>> and send to a jms queue.
>> > >>>> In the console log everything looks fine and the jms message has
>> been
>> > >>> sent.
>> > >>>> In the console log the id of the newly created BatchOrder record
is
>> > >>>> printed, but at the end when we check the database no record has
>> been
>> > >>>> created in the table BatchOrder.
>> > >>>>
>> > >>>> The classes involved are 3:
>> > >>>> BatchManager
>> > >>>> BatchOrderDao
>> > >>>> OverdueBatchTimerService
>> > >>>>
>> > >>>> Here is the following code snippet of my application.
>> > >>
>> >
>>
---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Stateless
>> > >>>> public class BatchManager{
>> > >>>>    @EJB
>> > >>>>    private BatchOrderDao batchOrderDao;
>> > >>>>
>> > >>>>    @Asynchronous
>> > >>>>    @Lock(LockType.READ)
>> > >>>>    public void createBatchMessage(...){
>> > >>>>        ...Some code to read Invoice table...
>> > >>>>
>> > >>>>        batchOrderDao.create(batchOrder);
>> > >>>>
>> > >>>>        ...Some more code to send jms message...
>> > >>>>
>> > >>>>    }
>> > >>>> }
>> > >>
>> >
>>
---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Stateless
>> > >>>> public class BatchOrderDao{
>> > >>>>
>> > >>>>    @PersistenceContext(unitName = "datasource")
>> > >>>>    private EntityManager entityManager;
>> > >>>>
>> > >>>>    public void create(BatchOrder entity){
>> > >>>>        entityManager.persist(entity);
>> > >>>>        entityManager.flush();
>> > >>>>    }
>> > >>>>
>> > >>>>    @SuppressWarnings("unchecked")
>> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date
>> date) {
>> > >>>>        final Criteria criteria =
>> > >>>> getSession().createCriteria(BatchOrder.class);
>> > >>
>> >
>>
criteria.setProjection(Projections.distinct(Projections.property("iId")));
>> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
>> > >>>>        ....Some more Restrictions.....
>> > >>>>        return criteria.list();
>> > >>>>    }
>> > >>>>
>> > >>>> }
>> > >>
>> >
>>
---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Entity
>> > >>>> @Cacheable
>> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
>> > >>>> @Table(name = "BATCH_ORDER")
>> > >>>> public class BatchOrder {
>> > >>>>  private static final long serialVersionUID = 1L;
>> > >>>>
>> > >>>>  @Id
>> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>> > >>> "IdSeq")
>> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
>> > >>>> allocationSize = 1)
>> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
>> updatable =
>> > >>>> false)
>> > >>>>  private Long iId;
>> > >>>>
>> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
>> > >> updatable
>> > >>>> = true)
>> > >>>>  private Date iAlarmed;
>> > >>>>
>> > >>>>  .... Some more fields....
>> > >>>>
>> > >>>> }
>> > >>
>> >
>>
---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Singleton
>> > >>>> @Startup
>> > >>>> @Lock(LockType.READ)
>> > >>>> private class OverdueBatchTimerService{
>> > >>>>    @Inject
>> > >>>>    private BatchOrderDao dao;
>> > >>>>    @Resource
>> > >>>>    private TimerService timerService;
>> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l
*
>> > >>> 1000l;
>> > >>>>
>> > >>>>    @PostConstruct
>> > >>>>    public void initialize() throws Exception {
>> > >>>>
>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
>> > >>>> new TimerConfig());
>> > >>>>    }
>> > >>>>
>> > >>>>    @Timeout
>> > >>>>    public void onTimeout(final Timer timer) {
>> > >>>>        try{
>> > >>>>            .. Some Code....
>> > >>>>            dao.findBatchesWithOverdueReceipts(time);
>> > >>>>            .... Some more code....
>> > >>>>        } catch (final Exception ignore) {
>> > >>>>            LOG.error("Some exception occured while excecuting
>> > >> onTimeout,
>> > >>>> but IGNORED.", ignore);
>> > >>>>        } finally {
>> > >>>>
>> > >>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
new
>> > >>>> TimerConfig());
>> > >>>>        }
>> > >>>>    }
>> > >>>> }
>> > >>
>> >
>>
---------------------------------------------------------------------------------------------------------------------------
>> > >>>>
>> > >>>> Please let me know if I am making any mistake.
>> > >>>>
>> > >>>>
>> > >>>> --
>> > >>>> Thanks and Regards
>> > >>>> N Radhakrishna Kalyan
>> > >>>>
>> > >>>> P:  +46 733 312 584
>> > >>>> http://about.me/nrkkalyan
>> > >>>> <http://about.me/nrkkalyan>
>> > >>
>> > >>
>> > >>
>> > >> --
>> > >> Thanks and Regards
>> > >> N Radhakrishna Kalyan
>> > >>
>> > >> P:  +46 733 312 584
>> > >> http://about.me/nrkkalyan
>> > >> <http://about.me/nrkkalyan>
>> > >>
>> >
>>
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>



--
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Hi,

Anyway after a while of reading and browsing I came to the following
conclusion. I have rewritten my BatchManager class to use
@TransactionManagement(TransactionManagementType.BEAN).


@Stateless
*@TransactionManagement(TransactionManagementType.BEAN)   *
public class BatchManager{
    @EJB
    private BatchOrderDao batchOrderDao;

    @Resource
    private UserTransaction userTransaction;

    @Asynchronous
    @Lock(LockType.READ)
    public void createBatchMessage(...){
    try{
        *userTransaction.begin();*
        ...Some code to read Invoice table...

        batchOrderDao.create(batchOrder);
        *userTransaction.commit();*

        ...Some more code to send jms message...
     } catch (final Throwable ignore) {
        ignore.printStackTrace();
     }

    }
}

This way I can be sure if the usertransaction is commited then the record
is created in the database and we can send jms message without any problem.

Please correct me if my approach is incorrect.

Regards
Kalyan




On Sun, Nov 2, 2014 at 1:18 PM, Radhakrishna Kalyan <nr...@gmail.com>
wrote:

> Hi,
>
> I am sorry, I am not clear, what do you mean by random execution order.
> Our requirement is, we have 2 tasks :
>
> *Task1:* The @Asynchronous method, BatchManager.createBatchMessage() is
> triggered by a different application through a http rest request.
>            As I mentioned previously, the goal of this method is to create
> a BatchOrder entity in database and send jms message by reading Invoices
> table, with all the invoices as xml to a different application. The reason
> to use @Asynchronous because the method can take 30-50 minutes to complete
> and we don't the http request to wait so long.
>
> *Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes to
> find all the batchorders with certain criteria and send an email if the
> criteria matches.
>
> If you observe in both tasks the common is the BatchOrder table. Task1 is
> inserting into that table and Task2 is selecting from that table.
>
> I believe that both tasks run in 2 different threads, so I am not clear
> how can an exception caused in Task2 caused rollback of the transaction in
> Task1.
> Is it possible?
>
>
>
>
>
> On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
>> I think async usage leadd to some random execution order. Ensure it is not
>> random then it should work
>> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
>>
>> > Hi
>> >
>> > Thank you. Can you please elaborate what do you mean by synchronously.
>> >
>> > Regards
>> > /Kalyan
>> > 0733312584
>> >
>> > PS: I am bad at spelling because I use mobile.
>> >
>> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com>
>> > wrote:
>> > >
>> > > This is an app exception and surely a timing issue. Rewrite the app
>> > > synchronously it will work so i sadly think it is on your side
>> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a
>> > écrit :
>> > >
>> > >> Sorry
>> > >> Please find the exception at the following url
>> > >>
>> > >>
>> > >>
>> >
>> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
>> > >>
>> > >>
>> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
>> > rmannibucau@gmail.com
>> > >> wrote:
>> > >>
>> > >>> Hi
>> > >>>
>> > >>> I dont see any attached file, can you gist or pastebin it?
>> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
>> > >> écrit
>> > >>> :
>> > >>>
>> > >>>>
>> > >>>>
>> > >>>> Hi,
>> > >>>>
>> > >>>> Yesterday we had deployed our application in our production for the
>> > >> first
>> > >>>> time which was developed using OpenEJB standalone.
>> > >>>> But we got an exception after a while when we tried to perform
>> certain
>> > >>>> operation.
>> > >>>> Please find the attached exception file.
>> > >>>>
>> > >>>> The application shall read certain data from a table(Invoice) in
>> > >> database
>> > >>>> and create an entry in an another table (BatchOrder). After that it
>> > >> shall
>> > >>>> create an xml message using that data
>> > >>>> and send to a jms queue.
>> > >>>> In the console log everything looks fine and the jms message has
>> been
>> > >>> sent.
>> > >>>> In the console log the id of the newly created BatchOrder record is
>> > >>>> printed, but at the end when we check the database no record has
>> been
>> > >>>> created in the table BatchOrder.
>> > >>>>
>> > >>>> The classes involved are 3:
>> > >>>> BatchManager
>> > >>>> BatchOrderDao
>> > >>>> OverdueBatchTimerService
>> > >>>>
>> > >>>> Here is the following code snippet of my application.
>> > >>
>> >
>> ---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Stateless
>> > >>>> public class BatchManager{
>> > >>>>    @EJB
>> > >>>>    private BatchOrderDao batchOrderDao;
>> > >>>>
>> > >>>>    @Asynchronous
>> > >>>>    @Lock(LockType.READ)
>> > >>>>    public void createBatchMessage(...){
>> > >>>>        ...Some code to read Invoice table...
>> > >>>>
>> > >>>>        batchOrderDao.create(batchOrder);
>> > >>>>
>> > >>>>        ...Some more code to send jms message...
>> > >>>>
>> > >>>>    }
>> > >>>> }
>> > >>
>> >
>> ---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Stateless
>> > >>>> public class BatchOrderDao{
>> > >>>>
>> > >>>>    @PersistenceContext(unitName = "datasource")
>> > >>>>    private EntityManager entityManager;
>> > >>>>
>> > >>>>    public void create(BatchOrder entity){
>> > >>>>        entityManager.persist(entity);
>> > >>>>        entityManager.flush();
>> > >>>>    }
>> > >>>>
>> > >>>>    @SuppressWarnings("unchecked")
>> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date
>> date) {
>> > >>>>        final Criteria criteria =
>> > >>>> getSession().createCriteria(BatchOrder.class);
>> > >>
>> >
>> criteria.setProjection(Projections.distinct(Projections.property("iId")));
>> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
>> > >>>>        ....Some more Restrictions.....
>> > >>>>        return criteria.list();
>> > >>>>    }
>> > >>>>
>> > >>>> }
>> > >>
>> >
>> ---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Entity
>> > >>>> @Cacheable
>> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
>> > >>>> @Table(name = "BATCH_ORDER")
>> > >>>> public class BatchOrder {
>> > >>>>  private static final long serialVersionUID = 1L;
>> > >>>>
>> > >>>>  @Id
>> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>> > >>> "IdSeq")
>> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
>> > >>>> allocationSize = 1)
>> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false,
>> updatable =
>> > >>>> false)
>> > >>>>  private Long iId;
>> > >>>>
>> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
>> > >> updatable
>> > >>>> = true)
>> > >>>>  private Date iAlarmed;
>> > >>>>
>> > >>>>  .... Some more fields....
>> > >>>>
>> > >>>> }
>> > >>
>> >
>> ---------------------------------------------------------------------------------------------------------------------------
>> > >>>> @Singleton
>> > >>>> @Startup
>> > >>>> @Lock(LockType.READ)
>> > >>>> private class OverdueBatchTimerService{
>> > >>>>    @Inject
>> > >>>>    private BatchOrderDao dao;
>> > >>>>    @Resource
>> > >>>>    private TimerService timerService;
>> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
>> > >>> 1000l;
>> > >>>>
>> > >>>>    @PostConstruct
>> > >>>>    public void initialize() throws Exception {
>> > >>>>
>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
>> > >>>> new TimerConfig());
>> > >>>>    }
>> > >>>>
>> > >>>>    @Timeout
>> > >>>>    public void onTimeout(final Timer timer) {
>> > >>>>        try{
>> > >>>>            .. Some Code....
>> > >>>>            dao.findBatchesWithOverdueReceipts(time);
>> > >>>>            .... Some more code....
>> > >>>>        } catch (final Exception ignore) {
>> > >>>>            LOG.error("Some exception occured while excecuting
>> > >> onTimeout,
>> > >>>> but IGNORED.", ignore);
>> > >>>>        } finally {
>> > >>>>
>> > >>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
>> > >>>> TimerConfig());
>> > >>>>        }
>> > >>>>    }
>> > >>>> }
>> > >>
>> >
>> ---------------------------------------------------------------------------------------------------------------------------
>> > >>>>
>> > >>>> Please let me know if I am making any mistake.
>> > >>>>
>> > >>>>
>> > >>>> --
>> > >>>> Thanks and Regards
>> > >>>> N Radhakrishna Kalyan
>> > >>>>
>> > >>>> P:  +46 733 312 584
>> > >>>> http://about.me/nrkkalyan
>> > >>>> <http://about.me/nrkkalyan>
>> > >>
>> > >>
>> > >>
>> > >> --
>> > >> Thanks and Regards
>> > >> N Radhakrishna Kalyan
>> > >>
>> > >> P:  +46 733 312 584
>> > >> http://about.me/nrkkalyan
>> > >> <http://about.me/nrkkalyan>
>> > >>
>> >
>>
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Hi,

I am sorry, I am not clear, what do you mean by random execution order.
Our requirement is, we have 2 tasks :

*Task1:* The @Asynchronous method, BatchManager.createBatchMessage() is
triggered by a different application through a http rest request.
           As I mentioned previously, the goal of this method is to create
a BatchOrder entity in database and send jms message by reading Invoices
table, with all the invoices as xml to a different application. The reason
to use @Asynchronous because the method can take 30-50 minutes to complete
and we don't the http request to wait so long.

*Task2:* OverdueBatchTimerService is scheduled to run every 5 minutes to
find all the batchorders with certain criteria and send an email if the
criteria matches.

If you observe in both tasks the common is the BatchOrder table. Task1 is
inserting into that table and Task2 is selecting from that table.

I believe that both tasks run in 2 different threads, so I am not clear how
can an exception caused in Task2 caused rollback of the transaction in
Task1.
Is it possible?





On Sun, Nov 2, 2014 at 8:45 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> I think async usage leadd to some random execution order. Ensure it is not
> random then it should work
> Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :
>
> > Hi
> >
> > Thank you. Can you please elaborate what do you mean by synchronously.
> >
> > Regards
> > /Kalyan
> > 0733312584
> >
> > PS: I am bad at spelling because I use mobile.
> >
> > > On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com>
> > wrote:
> > >
> > > This is an app exception and surely a timing issue. Rewrite the app
> > > synchronously it will work so i sadly think it is on your side
> > > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a
> > écrit :
> > >
> > >> Sorry
> > >> Please find the exception at the following url
> > >>
> > >>
> > >>
> >
> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> > >>
> > >>
> > >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> > rmannibucau@gmail.com
> > >> wrote:
> > >>
> > >>> Hi
> > >>>
> > >>> I dont see any attached file, can you gist or pastebin it?
> > >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
> > >> écrit
> > >>> :
> > >>>
> > >>>>
> > >>>>
> > >>>> Hi,
> > >>>>
> > >>>> Yesterday we had deployed our application in our production for the
> > >> first
> > >>>> time which was developed using OpenEJB standalone.
> > >>>> But we got an exception after a while when we tried to perform
> certain
> > >>>> operation.
> > >>>> Please find the attached exception file.
> > >>>>
> > >>>> The application shall read certain data from a table(Invoice) in
> > >> database
> > >>>> and create an entry in an another table (BatchOrder). After that it
> > >> shall
> > >>>> create an xml message using that data
> > >>>> and send to a jms queue.
> > >>>> In the console log everything looks fine and the jms message has
> been
> > >>> sent.
> > >>>> In the console log the id of the newly created BatchOrder record is
> > >>>> printed, but at the end when we check the database no record has
> been
> > >>>> created in the table BatchOrder.
> > >>>>
> > >>>> The classes involved are 3:
> > >>>> BatchManager
> > >>>> BatchOrderDao
> > >>>> OverdueBatchTimerService
> > >>>>
> > >>>> Here is the following code snippet of my application.
> > >>
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >>>> @Stateless
> > >>>> public class BatchManager{
> > >>>>    @EJB
> > >>>>    private BatchOrderDao batchOrderDao;
> > >>>>
> > >>>>    @Asynchronous
> > >>>>    @Lock(LockType.READ)
> > >>>>    public void createBatchMessage(...){
> > >>>>        ...Some code to read Invoice table...
> > >>>>
> > >>>>        batchOrderDao.create(batchOrder);
> > >>>>
> > >>>>        ...Some more code to send jms message...
> > >>>>
> > >>>>    }
> > >>>> }
> > >>
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >>>> @Stateless
> > >>>> public class BatchOrderDao{
> > >>>>
> > >>>>    @PersistenceContext(unitName = "datasource")
> > >>>>    private EntityManager entityManager;
> > >>>>
> > >>>>    public void create(BatchOrder entity){
> > >>>>        entityManager.persist(entity);
> > >>>>        entityManager.flush();
> > >>>>    }
> > >>>>
> > >>>>    @SuppressWarnings("unchecked")
> > >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date
> date) {
> > >>>>        final Criteria criteria =
> > >>>> getSession().createCriteria(BatchOrder.class);
> > >>
> >
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> > >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> > >>>>        ....Some more Restrictions.....
> > >>>>        return criteria.list();
> > >>>>    }
> > >>>>
> > >>>> }
> > >>
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >>>> @Entity
> > >>>> @Cacheable
> > >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > >>>> @Table(name = "BATCH_ORDER")
> > >>>> public class BatchOrder {
> > >>>>  private static final long serialVersionUID = 1L;
> > >>>>
> > >>>>  @Id
> > >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> > >>> "IdSeq")
> > >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> > >>>> allocationSize = 1)
> > >>>>  @Column(name = "BO_ID", unique = true, nullable = false, updatable
> =
> > >>>> false)
> > >>>>  private Long iId;
> > >>>>
> > >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
> > >> updatable
> > >>>> = true)
> > >>>>  private Date iAlarmed;
> > >>>>
> > >>>>  .... Some more fields....
> > >>>>
> > >>>> }
> > >>
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >>>> @Singleton
> > >>>> @Startup
> > >>>> @Lock(LockType.READ)
> > >>>> private class OverdueBatchTimerService{
> > >>>>    @Inject
> > >>>>    private BatchOrderDao dao;
> > >>>>    @Resource
> > >>>>    private TimerService timerService;
> > >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
> > >>> 1000l;
> > >>>>
> > >>>>    @PostConstruct
> > >>>>    public void initialize() throws Exception {
> > >>>>
> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > >>>> new TimerConfig());
> > >>>>    }
> > >>>>
> > >>>>    @Timeout
> > >>>>    public void onTimeout(final Timer timer) {
> > >>>>        try{
> > >>>>            .. Some Code....
> > >>>>            dao.findBatchesWithOverdueReceipts(time);
> > >>>>            .... Some more code....
> > >>>>        } catch (final Exception ignore) {
> > >>>>            LOG.error("Some exception occured while excecuting
> > >> onTimeout,
> > >>>> but IGNORED.", ignore);
> > >>>>        } finally {
> > >>>>
> > >>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> > >>>> TimerConfig());
> > >>>>        }
> > >>>>    }
> > >>>> }
> > >>
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >>>>
> > >>>> Please let me know if I am making any mistake.
> > >>>>
> > >>>>
> > >>>> --
> > >>>> Thanks and Regards
> > >>>> N Radhakrishna Kalyan
> > >>>>
> > >>>> P:  +46 733 312 584
> > >>>> http://about.me/nrkkalyan
> > >>>> <http://about.me/nrkkalyan>
> > >>
> > >>
> > >>
> > >> --
> > >> Thanks and Regards
> > >> N Radhakrishna Kalyan
> > >>
> > >> P:  +46 733 312 584
> > >> http://about.me/nrkkalyan
> > >> <http://about.me/nrkkalyan>
> > >>
> >
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I think async usage leadd to some random execution order. Ensure it is not
random then it should work
Le 2 nov. 2014 08:38, "Nrkkalyan" <nr...@gmail.com> a écrit :

> Hi
>
> Thank you. Can you please elaborate what do you mean by synchronously.
>
> Regards
> /Kalyan
> 0733312584
>
> PS: I am bad at spelling because I use mobile.
>
> > On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
> >
> > This is an app exception and surely a timing issue. Rewrite the app
> > synchronously it will work so i sadly think it is on your side
> > Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a
> écrit :
> >
> >> Sorry
> >> Please find the exception at the following url
> >>
> >>
> >>
> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
> >>
> >>
> >> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com
> >> wrote:
> >>
> >>> Hi
> >>>
> >>> I dont see any attached file, can you gist or pastebin it?
> >>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
> >> écrit
> >>> :
> >>>
> >>>>
> >>>>
> >>>> Hi,
> >>>>
> >>>> Yesterday we had deployed our application in our production for the
> >> first
> >>>> time which was developed using OpenEJB standalone.
> >>>> But we got an exception after a while when we tried to perform certain
> >>>> operation.
> >>>> Please find the attached exception file.
> >>>>
> >>>> The application shall read certain data from a table(Invoice) in
> >> database
> >>>> and create an entry in an another table (BatchOrder). After that it
> >> shall
> >>>> create an xml message using that data
> >>>> and send to a jms queue.
> >>>> In the console log everything looks fine and the jms message has been
> >>> sent.
> >>>> In the console log the id of the newly created BatchOrder record is
> >>>> printed, but at the end when we check the database no record has been
> >>>> created in the table BatchOrder.
> >>>>
> >>>> The classes involved are 3:
> >>>> BatchManager
> >>>> BatchOrderDao
> >>>> OverdueBatchTimerService
> >>>>
> >>>> Here is the following code snippet of my application.
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>>> @Stateless
> >>>> public class BatchManager{
> >>>>    @EJB
> >>>>    private BatchOrderDao batchOrderDao;
> >>>>
> >>>>    @Asynchronous
> >>>>    @Lock(LockType.READ)
> >>>>    public void createBatchMessage(...){
> >>>>        ...Some code to read Invoice table...
> >>>>
> >>>>        batchOrderDao.create(batchOrder);
> >>>>
> >>>>        ...Some more code to send jms message...
> >>>>
> >>>>    }
> >>>> }
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>>> @Stateless
> >>>> public class BatchOrderDao{
> >>>>
> >>>>    @PersistenceContext(unitName = "datasource")
> >>>>    private EntityManager entityManager;
> >>>>
> >>>>    public void create(BatchOrder entity){
> >>>>        entityManager.persist(entity);
> >>>>        entityManager.flush();
> >>>>    }
> >>>>
> >>>>    @SuppressWarnings("unchecked")
> >>>>    public List<Long> findBatchesWithOverdueReceipts(final Date date) {
> >>>>        final Criteria criteria =
> >>>> getSession().createCriteria(BatchOrder.class);
> >>
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> >>>>        criteria.add(Restrictions.isNull("iAlarmed"));
> >>>>        ....Some more Restrictions.....
> >>>>        return criteria.list();
> >>>>    }
> >>>>
> >>>> }
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>>> @Entity
> >>>> @Cacheable
> >>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> >>>> @Table(name = "BATCH_ORDER")
> >>>> public class BatchOrder {
> >>>>  private static final long serialVersionUID = 1L;
> >>>>
> >>>>  @Id
> >>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> >>> "IdSeq")
> >>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> >>>> allocationSize = 1)
> >>>>  @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> >>>> false)
> >>>>  private Long iId;
> >>>>
> >>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
> >> updatable
> >>>> = true)
> >>>>  private Date iAlarmed;
> >>>>
> >>>>  .... Some more fields....
> >>>>
> >>>> }
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>>> @Singleton
> >>>> @Startup
> >>>> @Lock(LockType.READ)
> >>>> private class OverdueBatchTimerService{
> >>>>    @Inject
> >>>>    private BatchOrderDao dao;
> >>>>    @Resource
> >>>>    private TimerService timerService;
> >>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
> >>> 1000l;
> >>>>
> >>>>    @PostConstruct
> >>>>    public void initialize() throws Exception {
> >>>>        timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> >>>> new TimerConfig());
> >>>>    }
> >>>>
> >>>>    @Timeout
> >>>>    public void onTimeout(final Timer timer) {
> >>>>        try{
> >>>>            .. Some Code....
> >>>>            dao.findBatchesWithOverdueReceipts(time);
> >>>>            .... Some more code....
> >>>>        } catch (final Exception ignore) {
> >>>>            LOG.error("Some exception occured while excecuting
> >> onTimeout,
> >>>> but IGNORED.", ignore);
> >>>>        } finally {
> >>>>
> >>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> >>>> TimerConfig());
> >>>>        }
> >>>>    }
> >>>> }
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>>>
> >>>> Please let me know if I am making any mistake.
> >>>>
> >>>>
> >>>> --
> >>>> Thanks and Regards
> >>>> N Radhakrishna Kalyan
> >>>>
> >>>> P:  +46 733 312 584
> >>>> http://about.me/nrkkalyan
> >>>> <http://about.me/nrkkalyan>
> >>
> >>
> >>
> >> --
> >> Thanks and Regards
> >> N Radhakrishna Kalyan
> >>
> >> P:  +46 733 312 584
> >> http://about.me/nrkkalyan
> >> <http://about.me/nrkkalyan>
> >>
>

Re: Exception while running openejb application

Posted by Nrkkalyan <nr...@gmail.com>.
Hi

Thank you. Can you please elaborate what do you mean by synchronously. 

Regards 
/Kalyan 
0733312584

PS: I am bad at spelling because I use mobile. 

> On 2 nov 2014, at 08:04, Romain Manni-Bucau <rm...@gmail.com> wrote:
> 
> This is an app exception and surely a timing issue. Rewrite the app
> synchronously it will work so i sadly think it is on your side
> Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :
> 
>> Sorry
>> Please find the exception at the following url
>> 
>> 
>> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
>> 
>> 
>> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <rmannibucau@gmail.com
>> wrote:
>> 
>>> Hi
>>> 
>>> I dont see any attached file, can you gist or pastebin it?
>>> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
>> écrit
>>> :
>>> 
>>>> 
>>>> 
>>>> Hi,
>>>> 
>>>> Yesterday we had deployed our application in our production for the
>> first
>>>> time which was developed using OpenEJB standalone.
>>>> But we got an exception after a while when we tried to perform certain
>>>> operation.
>>>> Please find the attached exception file.
>>>> 
>>>> The application shall read certain data from a table(Invoice) in
>> database
>>>> and create an entry in an another table (BatchOrder). After that it
>> shall
>>>> create an xml message using that data
>>>> and send to a jms queue.
>>>> In the console log everything looks fine and the jms message has been
>>> sent.
>>>> In the console log the id of the newly created BatchOrder record is
>>>> printed, but at the end when we check the database no record has been
>>>> created in the table BatchOrder.
>>>> 
>>>> The classes involved are 3:
>>>> BatchManager
>>>> BatchOrderDao
>>>> OverdueBatchTimerService
>>>> 
>>>> Here is the following code snippet of my application.
>> ---------------------------------------------------------------------------------------------------------------------------
>>>> @Stateless
>>>> public class BatchManager{
>>>>    @EJB
>>>>    private BatchOrderDao batchOrderDao;
>>>> 
>>>>    @Asynchronous
>>>>    @Lock(LockType.READ)
>>>>    public void createBatchMessage(...){
>>>>        ...Some code to read Invoice table...
>>>> 
>>>>        batchOrderDao.create(batchOrder);
>>>> 
>>>>        ...Some more code to send jms message...
>>>> 
>>>>    }
>>>> }
>> ---------------------------------------------------------------------------------------------------------------------------
>>>> @Stateless
>>>> public class BatchOrderDao{
>>>> 
>>>>    @PersistenceContext(unitName = "datasource")
>>>>    private EntityManager entityManager;
>>>> 
>>>>    public void create(BatchOrder entity){
>>>>        entityManager.persist(entity);
>>>>        entityManager.flush();
>>>>    }
>>>> 
>>>>    @SuppressWarnings("unchecked")
>>>>    public List<Long> findBatchesWithOverdueReceipts(final Date date) {
>>>>        final Criteria criteria =
>>>> getSession().createCriteria(BatchOrder.class);
>> criteria.setProjection(Projections.distinct(Projections.property("iId")));
>>>>        criteria.add(Restrictions.isNull("iAlarmed"));
>>>>        ....Some more Restrictions.....
>>>>        return criteria.list();
>>>>    }
>>>> 
>>>> }
>> ---------------------------------------------------------------------------------------------------------------------------
>>>> @Entity
>>>> @Cacheable
>>>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
>>>> @Table(name = "BATCH_ORDER")
>>>> public class BatchOrder {
>>>>  private static final long serialVersionUID = 1L;
>>>> 
>>>>  @Id
>>>>  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>>> "IdSeq")
>>>>  @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
>>>> allocationSize = 1)
>>>>  @Column(name = "BO_ID", unique = true, nullable = false, updatable =
>>>> false)
>>>>  private Long iId;
>>>> 
>>>>  @Column(name = "BO_ALARMED", unique = false, nullable = true,
>> updatable
>>>> = true)
>>>>  private Date iAlarmed;
>>>> 
>>>>  .... Some more fields....
>>>> 
>>>> }
>> ---------------------------------------------------------------------------------------------------------------------------
>>>> @Singleton
>>>> @Startup
>>>> @Lock(LockType.READ)
>>>> private class OverdueBatchTimerService{
>>>>    @Inject
>>>>    private BatchOrderDao dao;
>>>>    @Resource
>>>>    private TimerService timerService;
>>>>    private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
>>> 1000l;
>>>> 
>>>>    @PostConstruct
>>>>    public void initialize() throws Exception {
>>>>        timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
>>>> new TimerConfig());
>>>>    }
>>>> 
>>>>    @Timeout
>>>>    public void onTimeout(final Timer timer) {
>>>>        try{
>>>>            .. Some Code....
>>>>            dao.findBatchesWithOverdueReceipts(time);
>>>>            .... Some more code....
>>>>        } catch (final Exception ignore) {
>>>>            LOG.error("Some exception occured while excecuting
>> onTimeout,
>>>> but IGNORED.", ignore);
>>>>        } finally {
>>>> 
>>>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
>>>> TimerConfig());
>>>>        }
>>>>    }
>>>> }
>> ---------------------------------------------------------------------------------------------------------------------------
>>>> 
>>>> Please let me know if I am making any mistake.
>>>> 
>>>> 
>>>> --
>>>> Thanks and Regards
>>>> N Radhakrishna Kalyan
>>>> 
>>>> P:  +46 733 312 584
>>>> http://about.me/nrkkalyan
>>>> <http://about.me/nrkkalyan>
>> 
>> 
>> 
>> --
>> Thanks and Regards
>> N Radhakrishna Kalyan
>> 
>> P:  +46 733 312 584
>> http://about.me/nrkkalyan
>> <http://about.me/nrkkalyan>
>> 

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
This is an app exception and surely a timing issue. Rewrite the app
synchronously it will work so i sadly think it is on your side
Le 1 nov. 2014 22:24, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :

> Sorry
> Please find the exception at the following url
>
>
> https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing
>
>
> On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <rmannibucau@gmail.com
> >
> wrote:
>
> > Hi
> >
> > I dont see any attached file, can you gist or pastebin it?
> > Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a
> écrit
> > :
> >
> > >
> > >
> > > Hi,
> > >
> > > Yesterday we had deployed our application in our production for the
> first
> > > time which was developed using OpenEJB standalone.
> > > But we got an exception after a while when we tried to perform certain
> > > operation.
> > > Please find the attached exception file.
> > >
> > > The application shall read certain data from a table(Invoice) in
> database
> > > and create an entry in an another table (BatchOrder). After that it
> shall
> > > create an xml message using that data
> > > and send to a jms queue.
> > > In the console log everything looks fine and the jms message has been
> > sent.
> > > In the console log the id of the newly created BatchOrder record is
> > > printed, but at the end when we check the database no record has been
> > > created in the table BatchOrder.
> > >
> > > The classes involved are 3:
> > > BatchManager
> > > BatchOrderDao
> > > OverdueBatchTimerService
> > >
> > > Here is the following code snippet of my application.
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > > @Stateless
> > > public class BatchManager{
> > >     @EJB
> > >     private BatchOrderDao batchOrderDao;
> > >
> > >     @Asynchronous
> > >     @Lock(LockType.READ)
> > >     public void createBatchMessage(...){
> > >         ...Some code to read Invoice table...
> > >
> > >         batchOrderDao.create(batchOrder);
> > >
> > >         ...Some more code to send jms message...
> > >
> > >     }
> > > }
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > > @Stateless
> > > public class BatchOrderDao{
> > >
> > >     @PersistenceContext(unitName = "datasource")
> > >     private EntityManager entityManager;
> > >
> > >     public void create(BatchOrder entity){
> > >         entityManager.persist(entity);
> > >         entityManager.flush();
> > >     }
> > >
> > >     @SuppressWarnings("unchecked")
> > >     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
> > >         final Criteria criteria =
> > > getSession().createCriteria(BatchOrder.class);
> > >
> > >
> >
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> > >         criteria.add(Restrictions.isNull("iAlarmed"));
> > >         ....Some more Restrictions.....
> > >         return criteria.list();
> > >     }
> > >
> > > }
> > >
> > >
> > >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > > @Entity
> > > @Cacheable
> > > @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > > @Table(name = "BATCH_ORDER")
> > > public class BatchOrder {
> > >   private static final long serialVersionUID = 1L;
> > >
> > >   @Id
> > >   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> > "IdSeq")
> > >   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> > > allocationSize = 1)
> > >   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> > > false)
> > >   private Long iId;
> > >
> > >   @Column(name = "BO_ALARMED", unique = false, nullable = true,
> updatable
> > > = true)
> > >   private Date iAlarmed;
> > >
> > >   .... Some more fields....
> > >
> > > }
> > >
> > >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > > @Singleton
> > > @Startup
> > > @Lock(LockType.READ)
> > > private class OverdueBatchTimerService{
> > >     @Inject
> > >     private BatchOrderDao dao;
> > >     @Resource
> > >     private TimerService timerService;
> > >     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
> > 1000l;
> > >
> > >     @PostConstruct
> > >     public void initialize() throws Exception {
> > >         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > > new TimerConfig());
> > >     }
> > >
> > >     @Timeout
> > >     public void onTimeout(final Timer timer) {
> > >         try{
> > >             .. Some Code....
> > >             dao.findBatchesWithOverdueReceipts(time);
> > >             .... Some more code....
> > >         } catch (final Exception ignore) {
> > >             LOG.error("Some exception occured while excecuting
> onTimeout,
> > > but IGNORED.", ignore);
> > >         } finally {
> > >
> > > timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> > > TimerConfig());
> > >         }
> > >     }
> > > }
> > >
> > >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > >
> > > Please let me know if I am making any mistake.
> > >
> > >
> > > --
> > > Thanks and Regards
> > > N Radhakrishna Kalyan
> > >
> > > P:  +46 733 312 584
> > > http://about.me/nrkkalyan
> > > <http://about.me/nrkkalyan>
> > >
> >
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Sorry
Please find the exception at the following url

https://drive.google.com/file/d/0B9j0dIS5bS0wYy1OOE5iaFNKaUU/view?usp=sharing


On Sat, Nov 1, 2014 at 10:20 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hi
>
> I dont see any attached file, can you gist or pastebin it?
> Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit
> :
>
> >
> >
> > Hi,
> >
> > Yesterday we had deployed our application in our production for the first
> > time which was developed using OpenEJB standalone.
> > But we got an exception after a while when we tried to perform certain
> > operation.
> > Please find the attached exception file.
> >
> > The application shall read certain data from a table(Invoice) in database
> > and create an entry in an another table (BatchOrder). After that it shall
> > create an xml message using that data
> > and send to a jms queue.
> > In the console log everything looks fine and the jms message has been
> sent.
> > In the console log the id of the newly created BatchOrder record is
> > printed, but at the end when we check the database no record has been
> > created in the table BatchOrder.
> >
> > The classes involved are 3:
> > BatchManager
> > BatchOrderDao
> > OverdueBatchTimerService
> >
> > Here is the following code snippet of my application.
> >
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > @Stateless
> > public class BatchManager{
> >     @EJB
> >     private BatchOrderDao batchOrderDao;
> >
> >     @Asynchronous
> >     @Lock(LockType.READ)
> >     public void createBatchMessage(...){
> >         ...Some code to read Invoice table...
> >
> >         batchOrderDao.create(batchOrder);
> >
> >         ...Some more code to send jms message...
> >
> >     }
> > }
> >
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > @Stateless
> > public class BatchOrderDao{
> >
> >     @PersistenceContext(unitName = "datasource")
> >     private EntityManager entityManager;
> >
> >     public void create(BatchOrder entity){
> >         entityManager.persist(entity);
> >         entityManager.flush();
> >     }
> >
> >     @SuppressWarnings("unchecked")
> >     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
> >         final Criteria criteria =
> > getSession().createCriteria(BatchOrder.class);
> >
> >
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> >         criteria.add(Restrictions.isNull("iAlarmed"));
> >         ....Some more Restrictions.....
> >         return criteria.list();
> >     }
> >
> > }
> >
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > @Entity
> > @Cacheable
> > @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> > @Table(name = "BATCH_ORDER")
> > public class BatchOrder {
> >   private static final long serialVersionUID = 1L;
> >
> >   @Id
> >   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "IdSeq")
> >   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> > allocationSize = 1)
> >   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> > false)
> >   private Long iId;
> >
> >   @Column(name = "BO_ALARMED", unique = false, nullable = true, updatable
> > = true)
> >   private Date iAlarmed;
> >
> >   .... Some more fields....
> >
> > }
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> > @Singleton
> > @Startup
> > @Lock(LockType.READ)
> > private class OverdueBatchTimerService{
> >     @Inject
> >     private BatchOrderDao dao;
> >     @Resource
> >     private TimerService timerService;
> >     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
> 1000l;
> >
> >     @PostConstruct
> >     public void initialize() throws Exception {
> >         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> > new TimerConfig());
> >     }
> >
> >     @Timeout
> >     public void onTimeout(final Timer timer) {
> >         try{
> >             .. Some Code....
> >             dao.findBatchesWithOverdueReceipts(time);
> >             .... Some more code....
> >         } catch (final Exception ignore) {
> >             LOG.error("Some exception occured while excecuting onTimeout,
> > but IGNORED.", ignore);
> >         } finally {
> >
> > timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> > TimerConfig());
> >         }
> >     }
> > }
> >
> >
> ---------------------------------------------------------------------------------------------------------------------------
> >
> > Please let me know if I am making any mistake.
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
> >
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

I dont see any attached file, can you gist or pastebin it?
Le 1 nov. 2014 21:23, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :

>
>
> Hi,
>
> Yesterday we had deployed our application in our production for the first
> time which was developed using OpenEJB standalone.
> But we got an exception after a while when we tried to perform certain
> operation.
> Please find the attached exception file.
>
> The application shall read certain data from a table(Invoice) in database
> and create an entry in an another table (BatchOrder). After that it shall
> create an xml message using that data
> and send to a jms queue.
> In the console log everything looks fine and the jms message has been sent.
> In the console log the id of the newly created BatchOrder record is
> printed, but at the end when we check the database no record has been
> created in the table BatchOrder.
>
> The classes involved are 3:
> BatchManager
> BatchOrderDao
> OverdueBatchTimerService
>
> Here is the following code snippet of my application.
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Stateless
> public class BatchManager{
>     @EJB
>     private BatchOrderDao batchOrderDao;
>
>     @Asynchronous
>     @Lock(LockType.READ)
>     public void createBatchMessage(...){
>         ...Some code to read Invoice table...
>
>         batchOrderDao.create(batchOrder);
>
>         ...Some more code to send jms message...
>
>     }
> }
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Stateless
> public class BatchOrderDao{
>
>     @PersistenceContext(unitName = "datasource")
>     private EntityManager entityManager;
>
>     public void create(BatchOrder entity){
>         entityManager.persist(entity);
>         entityManager.flush();
>     }
>
>     @SuppressWarnings("unchecked")
>     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
>         final Criteria criteria =
> getSession().createCriteria(BatchOrder.class);
>
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
>         criteria.add(Restrictions.isNull("iAlarmed"));
>         ....Some more Restrictions.....
>         return criteria.list();
>     }
>
> }
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Entity
> @Cacheable
> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> @Table(name = "BATCH_ORDER")
> public class BatchOrder {
>   private static final long serialVersionUID = 1L;
>
>   @Id
>   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
>   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> allocationSize = 1)
>   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> false)
>   private Long iId;
>
>   @Column(name = "BO_ALARMED", unique = false, nullable = true, updatable
> = true)
>   private Date iAlarmed;
>
>   .... Some more fields....
>
> }
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Singleton
> @Startup
> @Lock(LockType.READ)
> private class OverdueBatchTimerService{
>     @Inject
>     private BatchOrderDao dao;
>     @Resource
>     private TimerService timerService;
>     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l * 1000l;
>
>     @PostConstruct
>     public void initialize() throws Exception {
>         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> new TimerConfig());
>     }
>
>     @Timeout
>     public void onTimeout(final Timer timer) {
>         try{
>             .. Some Code....
>             dao.findBatchesWithOverdueReceipts(time);
>             .... Some more code....
>         } catch (final Exception ignore) {
>             LOG.error("Some exception occured while excecuting onTimeout,
> but IGNORED.", ignore);
>         } finally {
>
> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> TimerConfig());
>         }
>     }
> }
>
> ---------------------------------------------------------------------------------------------------------------------------
>
> Please let me know if I am making any mistake.
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Hi Romain,

@Lock is on OverdueBatchTimerService which is declared with @Singleton.
Do you mean to say that we can not use @Stateless classes in any other
class which is declared with @Lock?

I too guess that it may be a timing issue. We have not configured any kind
of thread management.
Can you please provide any pointers how to solve the timing issue?

More over if you have observed there is one more exception. I am not clear
why does this happen.
    org.apache.openejb.core.timer.TimerStoreException: Transaction has been

This was caused in the finally block while performing
@Timeout
    public void onTimeout(final Timer timer) {
        try{
            .. Some Code....
            dao.findBatchesWithOverdueReceipts(time);
            .... Some more code....
        } catch (final Exception ignore) {
            LOG.error("Some exception occured while excecuting onTimeout,
but IGNORED.", ignore);
        } finally {
            *timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
new TimerConfig());*
        }
    }

My intention is to create a timer service to run every 5 mins to perform
certain task. I have created single action timer only to make sure if the
task takes more than 5 mins (i.e 10 mins) then a new timer task should not
start in the 10th minute, before even completing the first schedule task.


Thanks in advance.

Regards.
Kalyan





On Sat, Nov 1, 2014 at 10:26 PM, Romain Manni-Bucau <
rmannibucau@tomitribe.com> wrote:

> First stateless and @lock is not useful.
>
> Then i guess you just have a timing issue due to the use of asynch. Did you
> configure it? Default is 3 threads, can be too few for you.
> Le 1 nov. 2014 22:21, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit
> :
>
> > Sorry if anyone is missing the attachment file.
> >
> >
> > On Sat, Nov 1, 2014 at 9:22 PM, Radhakrishna Kalyan <nrkkalyan@gmail.com
> >
> > wrote:
> >
> >>
> >>
> >> Hi,
> >>
> >> Yesterday we had deployed our application in our production for the
> first
> >> time which was developed using OpenEJB standalone.
> >> But we got an exception after a while when we tried to perform certain
> >> operation.
> >> Please find the attached exception file.
> >>
> >> The application shall read certain data from a table(Invoice) in
> database
> >> and create an entry in an another table (BatchOrder). After that it
> shall
> >> create an xml message using that data
> >> and send to a jms queue.
> >> In the console log everything looks fine and the jms message has been
> >> sent.
> >> In the console log the id of the newly created BatchOrder record is
> >> printed, but at the end when we check the database no record has been
> >> created in the table BatchOrder.
> >>
> >> The classes involved are 3:
> >> BatchManager
> >> BatchOrderDao
> >> OverdueBatchTimerService
> >>
> >> Here is the following code snippet of my application.
> >>
> >>
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >> @Stateless
> >> public class BatchManager{
> >>     @EJB
> >>     private BatchOrderDao batchOrderDao;
> >>
> >>     @Asynchronous
> >>     @Lock(LockType.READ)
> >>     public void createBatchMessage(...){
> >>         ...Some code to read Invoice table...
> >>
> >>         batchOrderDao.create(batchOrder);
> >>
> >>         ...Some more code to send jms message...
> >>
> >>     }
> >> }
> >>
> >>
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >> @Stateless
> >> public class BatchOrderDao{
> >>
> >>     @PersistenceContext(unitName = "datasource")
> >>     private EntityManager entityManager;
> >>
> >>     public void create(BatchOrder entity){
> >>         entityManager.persist(entity);
> >>         entityManager.flush();
> >>     }
> >>
> >>     @SuppressWarnings("unchecked")
> >>     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
> >>         final Criteria criteria =
> >> getSession().createCriteria(BatchOrder.class);
> >>
> >>
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
> >>         criteria.add(Restrictions.isNull("iAlarmed"));
> >>         ....Some more Restrictions.....
> >>         return criteria.list();
> >>     }
> >>
> >> }
> >>
> >>
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >> @Entity
> >> @Cacheable
> >> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> >> @Table(name = "BATCH_ORDER")
> >> public class BatchOrder {
> >>   private static final long serialVersionUID = 1L;
> >>
> >>   @Id
> >>   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "IdSeq")
> >>   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> >> allocationSize = 1)
> >>   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> >> false)
> >>   private Long iId;
> >>
> >>   @Column(name = "BO_ALARMED", unique = false, nullable = true,
> updatable
> >> = true)
> >>   private Date iAlarmed;
> >>
> >>   .... Some more fields....
> >>
> >> }
> >>
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >> @Singleton
> >> @Startup
> >> @Lock(LockType.READ)
> >> private class OverdueBatchTimerService{
> >>     @Inject
> >>     private BatchOrderDao dao;
> >>     @Resource
> >>     private TimerService timerService;
> >>     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
> >> 1000l;
> >>
> >>     @PostConstruct
> >>     public void initialize() throws Exception {
> >>         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> >> new TimerConfig());
> >>     }
> >>
> >>     @Timeout
> >>     public void onTimeout(final Timer timer) {
> >>         try{
> >>             .. Some Code....
> >>             dao.findBatchesWithOverdueReceipts(time);
> >>             .... Some more code....
> >>         } catch (final Exception ignore) {
> >>             LOG.error("Some exception occured while excecuting
> onTimeout,
> >> but IGNORED.", ignore);
> >>         } finally {
> >>
> >> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> >> TimerConfig());
> >>         }
> >>     }
> >> }
> >>
> >>
> ---------------------------------------------------------------------------------------------------------------------------
> >>
> >> Please let me know if I am making any mistake.
> >>
> >>
> >> --
> >> Thanks and Regards
> >> N Radhakrishna Kalyan
> >>
> >> P:  +46 733 312 584
> >> http://about.me/nrkkalyan
> >> <http://about.me/nrkkalyan>
> >>
> >
> >
> >
> > --
> > Thanks and Regards
> > N Radhakrishna Kalyan
> >
> > P:  +46 733 312 584
> > http://about.me/nrkkalyan
> > <http://about.me/nrkkalyan>
> >
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>

Re: Exception while running openejb application

Posted by Romain Manni-Bucau <rm...@tomitribe.com>.
First stateless and @lock is not useful.

Then i guess you just have a timing issue due to the use of asynch. Did you
configure it? Default is 3 threads, can be too few for you.
Le 1 nov. 2014 22:21, "Radhakrishna Kalyan" <nr...@gmail.com> a écrit :

> Sorry if anyone is missing the attachment file.
>
>
> On Sat, Nov 1, 2014 at 9:22 PM, Radhakrishna Kalyan <nr...@gmail.com>
> wrote:
>
>>
>>
>> Hi,
>>
>> Yesterday we had deployed our application in our production for the first
>> time which was developed using OpenEJB standalone.
>> But we got an exception after a while when we tried to perform certain
>> operation.
>> Please find the attached exception file.
>>
>> The application shall read certain data from a table(Invoice) in database
>> and create an entry in an another table (BatchOrder). After that it shall
>> create an xml message using that data
>> and send to a jms queue.
>> In the console log everything looks fine and the jms message has been
>> sent.
>> In the console log the id of the newly created BatchOrder record is
>> printed, but at the end when we check the database no record has been
>> created in the table BatchOrder.
>>
>> The classes involved are 3:
>> BatchManager
>> BatchOrderDao
>> OverdueBatchTimerService
>>
>> Here is the following code snippet of my application.
>>
>>
>> ---------------------------------------------------------------------------------------------------------------------------
>> @Stateless
>> public class BatchManager{
>>     @EJB
>>     private BatchOrderDao batchOrderDao;
>>
>>     @Asynchronous
>>     @Lock(LockType.READ)
>>     public void createBatchMessage(...){
>>         ...Some code to read Invoice table...
>>
>>         batchOrderDao.create(batchOrder);
>>
>>         ...Some more code to send jms message...
>>
>>     }
>> }
>>
>>
>> ---------------------------------------------------------------------------------------------------------------------------
>> @Stateless
>> public class BatchOrderDao{
>>
>>     @PersistenceContext(unitName = "datasource")
>>     private EntityManager entityManager;
>>
>>     public void create(BatchOrder entity){
>>         entityManager.persist(entity);
>>         entityManager.flush();
>>     }
>>
>>     @SuppressWarnings("unchecked")
>>     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
>>         final Criteria criteria =
>> getSession().createCriteria(BatchOrder.class);
>>
>> criteria.setProjection(Projections.distinct(Projections.property("iId")));
>>         criteria.add(Restrictions.isNull("iAlarmed"));
>>         ....Some more Restrictions.....
>>         return criteria.list();
>>     }
>>
>> }
>>
>>
>> ---------------------------------------------------------------------------------------------------------------------------
>> @Entity
>> @Cacheable
>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
>> @Table(name = "BATCH_ORDER")
>> public class BatchOrder {
>>   private static final long serialVersionUID = 1L;
>>
>>   @Id
>>   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
>>   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
>> allocationSize = 1)
>>   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
>> false)
>>   private Long iId;
>>
>>   @Column(name = "BO_ALARMED", unique = false, nullable = true, updatable
>> = true)
>>   private Date iAlarmed;
>>
>>   .... Some more fields....
>>
>> }
>>
>> ---------------------------------------------------------------------------------------------------------------------------
>> @Singleton
>> @Startup
>> @Lock(LockType.READ)
>> private class OverdueBatchTimerService{
>>     @Inject
>>     private BatchOrderDao dao;
>>     @Resource
>>     private TimerService timerService;
>>     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l *
>> 1000l;
>>
>>     @PostConstruct
>>     public void initialize() throws Exception {
>>         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
>> new TimerConfig());
>>     }
>>
>>     @Timeout
>>     public void onTimeout(final Timer timer) {
>>         try{
>>             .. Some Code....
>>             dao.findBatchesWithOverdueReceipts(time);
>>             .... Some more code....
>>         } catch (final Exception ignore) {
>>             LOG.error("Some exception occured while excecuting onTimeout,
>> but IGNORED.", ignore);
>>         } finally {
>>
>> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
>> TimerConfig());
>>         }
>>     }
>> }
>>
>> ---------------------------------------------------------------------------------------------------------------------------
>>
>> Please let me know if I am making any mistake.
>>
>>
>> --
>> Thanks and Regards
>> N Radhakrishna Kalyan
>>
>> P:  +46 733 312 584
>> http://about.me/nrkkalyan
>> <http://about.me/nrkkalyan>
>>
>
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>

Re: Exception while running openejb application

Posted by Radhakrishna Kalyan <nr...@gmail.com>.
Sorry if anyone is missing the attachment file.


On Sat, Nov 1, 2014 at 9:22 PM, Radhakrishna Kalyan <nr...@gmail.com>
wrote:

>
>
> Hi,
>
> Yesterday we had deployed our application in our production for the first
> time which was developed using OpenEJB standalone.
> But we got an exception after a while when we tried to perform certain
> operation.
> Please find the attached exception file.
>
> The application shall read certain data from a table(Invoice) in database
> and create an entry in an another table (BatchOrder). After that it shall
> create an xml message using that data
> and send to a jms queue.
> In the console log everything looks fine and the jms message has been sent.
> In the console log the id of the newly created BatchOrder record is
> printed, but at the end when we check the database no record has been
> created in the table BatchOrder.
>
> The classes involved are 3:
> BatchManager
> BatchOrderDao
> OverdueBatchTimerService
>
> Here is the following code snippet of my application.
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Stateless
> public class BatchManager{
>     @EJB
>     private BatchOrderDao batchOrderDao;
>
>     @Asynchronous
>     @Lock(LockType.READ)
>     public void createBatchMessage(...){
>         ...Some code to read Invoice table...
>
>         batchOrderDao.create(batchOrder);
>
>         ...Some more code to send jms message...
>
>     }
> }
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Stateless
> public class BatchOrderDao{
>
>     @PersistenceContext(unitName = "datasource")
>     private EntityManager entityManager;
>
>     public void create(BatchOrder entity){
>         entityManager.persist(entity);
>         entityManager.flush();
>     }
>
>     @SuppressWarnings("unchecked")
>     public List<Long> findBatchesWithOverdueReceipts(final Date date) {
>         final Criteria criteria =
> getSession().createCriteria(BatchOrder.class);
>
> criteria.setProjection(Projections.distinct(Projections.property("iId")));
>         criteria.add(Restrictions.isNull("iAlarmed"));
>         ....Some more Restrictions.....
>         return criteria.list();
>     }
>
> }
>
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Entity
> @Cacheable
> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
> @Table(name = "BATCH_ORDER")
> public class BatchOrder {
>   private static final long serialVersionUID = 1L;
>
>   @Id
>   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
>   @SequenceGenerator(name = "IdSeq", sequenceName = "BOID_SEQ",
> allocationSize = 1)
>   @Column(name = "BO_ID", unique = true, nullable = false, updatable =
> false)
>   private Long iId;
>
>   @Column(name = "BO_ALARMED", unique = false, nullable = true, updatable
> = true)
>   private Date iAlarmed;
>
>   .... Some more fields....
>
> }
>
> ---------------------------------------------------------------------------------------------------------------------------
> @Singleton
> @Startup
> @Lock(LockType.READ)
> private class OverdueBatchTimerService{
>     @Inject
>     private BatchOrderDao dao;
>     @Resource
>     private TimerService timerService;
>     private static final long _5MINUTES_IN_MILLISECONDS = 5l * 60l * 1000l;
>
>     @PostConstruct
>     public void initialize() throws Exception {
>         timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS,
> new TimerConfig());
>     }
>
>     @Timeout
>     public void onTimeout(final Timer timer) {
>         try{
>             .. Some Code....
>             dao.findBatchesWithOverdueReceipts(time);
>             .... Some more code....
>         } catch (final Exception ignore) {
>             LOG.error("Some exception occured while excecuting onTimeout,
> but IGNORED.", ignore);
>         } finally {
>
> timerService.createSingleActionTimer(_5MINUTES_IN_MILLISECONDS, new
> TimerConfig());
>         }
>     }
> }
>
> ---------------------------------------------------------------------------------------------------------------------------
>
> Please let me know if I am making any mistake.
>
>
> --
> Thanks and Regards
> N Radhakrishna Kalyan
>
> P:  +46 733 312 584
> http://about.me/nrkkalyan
> <http://about.me/nrkkalyan>
>



-- 
Thanks and Regards
N Radhakrishna Kalyan

P:  +46 733 312 584
http://about.me/nrkkalyan
<http://about.me/nrkkalyan>