9 Replies Latest reply on Jun 12, 2012 11:44 AM by Andy Taylor

    Randomly entity not found 'onMessage'

    marhat Newbie



      I have a question concerning HornetQ running in JBoss 6.0.0.


      I have a scenario whereby I want to track a series of messages posted to hornetq in an "ImportLog" entity I have created. To give a little further detail, the messages posted to HornetQ contain records that are to be imported into the database. For performance reasons, we like to limit the batch of records inserted at any one time. If our limit is 500 and a user decides to import 2000, we would create 4 messages for example.


      The ImportLog is a simple entity that helps us track and record stats of the import as a whole. So each message that processes will load the ImportLog entity and potentially update. The import queue has the maxSessions property set to 1, which means that the messages correctly process one-at-a-time.


      Before any messages are posted to HornetQ, the ImportLog entity is created. The id of the ImportLog entity is then passed as part of the object message.


      Radomly, everything will work perfectly fine. However, very frustratingly, the first message picked up will often claim that it cannot find the ImportLog entity (i.e. ImportLog log = em.find(ImportLog, id)). It appears that the message is being consumed before Hibernate has committed the import log to the database? Interestingly subsequent messages will find the ImportLog perfectly.


      I have tried various things to "force" hibernate to commit the entity so that the first message will always find the entity in the database. This includes calling flush(), manually committing the transaction after the ImportLog entity is initially created, along with other tricks I have read about that include calling session.evict() and session.update().


      Has anybody else found this problem? Is there a way to overcome or am I missing something / abusing functionality here?


      Any thoughts would be greatly appreciated