-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Entity Manager with BMT and Transaction Timeout
PostPosted: Thu Feb 25, 2010 12:53 pm 
Newbie

Joined: Thu Feb 12, 2009 10:00 am
Posts: 18
When running small loads on our application all is working fine, however under heavy concurrent load we consistently get the following exception.

Quote:
2010-02-09 12:40:56,773 FATAL [com.abc.IndexOutputStream.deliverJob] failed to lazily initialize a collection of role: com.abc.entities.ChannelJob.m_jobProperties, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.abc.entities.ChannelJob.m_jobProperties, no session or session was closed


My suspicious were that the underlying JTA transaction has timed-out and that the entity manager session was closed, so I tried increasing the global transaction timeout from 300 to 3600 in jboss-service.xml

Code:
   <!-- JBoss Transactions JTA -->
   <mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
      name="jboss:service=TransactionManager">
      <attribute name="TransactionTimeout">3600</attribute>
      <attribute name="ObjectStoreDir">${jboss.server.data.dir}/tx-object-store</attribute>
   </mbean>


However this did not resolve my problem. Shortly (between 5 to 10 minutes) after starting the transaction the same exception occured again. I am injecting a UserTransaction as well as an EntityManager into a MessageDrivenBean and then manage the transaction myself. I found some posts that suggest in this case I have to join the EntityManager to the JTA transaction using entityManger.joinTransaction() which I wasn't doing up to this point however this had little impact and the problem persists.

What I am looking for is some clarification on if this is really the case that I have to join the transaction and if I don't join where the timeout for the entity manager is configured. I had a look at the Hibernate documentation, but didn't find any reference to a timeout, other then on the entity cache.

I understand that this problem my not directly be linked to hibernate as I am using the hibernate entity manager within JBoss 4.2.3GA. I do however hope that somebody can point me in the right direction on how to further analyze this issue

Thanks in advance
Alex


Top
 Profile  
 
 Post subject: Re: Entity Manager with BMT and Transaction Timeout
PostPosted: Thu Feb 25, 2010 12:57 pm 
Newbie

Joined: Thu Feb 12, 2009 10:00 am
Posts: 18
First the MDB which shows the injection of an entityManager, usertransaction and a datasource:
Code:
...
@MessageDriven(name = "WorkListener", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/abc/WorkMessages")
})
@TransactionManagement(TransactionManagementType.BEAN)
public class WorkListener  implements MessageListener {

    @PersistenceContext(unitName = "entityManager")
    protected EntityManager entityManager;

    @Resource(name = "jdbc/abcDSNoTX")
    DataSource datasource;

    @Resource
    private UserTransaction userTransaction;

    public void onMessage(Message message) {
        try {         
            Processor processor = new Processor(entityManager, userTransaction, datasource);
            processor.process(message);
....


Then further down the stack we begin a new userTransaction and load some entity via the entity manager

Code:
...
m_userTransaction.begin();
Account account = m_entityManager.find(Account.class, accountId);
...
account.getRelatedAccounts();


However further down the stack we access a collection on the account which loads further linked entities and failes with the LazyInitializationException.

This problem only occurs under load and is most likely caused by a slow down while accessing the database. However I am not too concerned about performance at this stage, just want to know how I can debug this issue and see what happened to my entity manager session. My suspicion is that since I am using a User Transaction that the global timeout which I set to 3600 (=1 hour) is not applied. If this is the case where do you set the default transaction timeout for a user transaction or the hibernate session.

PS: I am using this code to illustrate my problem. I know the exception refers to a different class. The application consists of various different classes and posting the actual code would just make things more difficult.


Top
 Profile  
 
 Post subject: Re: Entity Manager with BMT and Transaction Timeout
PostPosted: Thu Feb 25, 2010 10:30 pm 
Newbie

Joined: Thu Feb 12, 2009 10:00 am
Posts: 18
I enabled the complete hibernate context at trace level and got the following. Not really sure what to look for:

Code:
2010-02-25 23:09:00,600 TRACE [org.hibernate.transaction.CacheSynchronization] transaction before completion callback
2010-02-25 23:09:00,600 TRACE [org.hibernate.jdbc.JDBCContext] before transaction completion
2010-02-25 23:09:00,601 TRACE [org.hibernate.impl.SessionImpl] before transaction completion
2010-02-25 23:09:00,601 TRACE [org.hibernate.ejb.AbstractEntityManagerImpl] automatically flushing session
2010-02-25 23:09:00,601 TRACE [org.hibernate.impl.SessionImpl] automatically flushing session
2010-02-25 23:09:00,601 TRACE [org.hibernate.event.def.AbstractFlushingEventListener] flushing session
2010-02-25 23:09:00,601 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] processing flush-time cascades
2010-02-25 23:09:00,601 TRACE [org.hibernate.engine.Cascade] processing cascade ACTION_PERSIST_ON_FLUSH for: com.abc.entities.Batch
2010-02-25 23:09:00,601 TRACE [org.hibernate.engine.Cascade] done processing cascade ACTION_PERSIST_ON_FLUSH for: com.abc.entities.Batch
2010-02-25 23:09:00,601 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] dirty checking collections
2010-02-25 23:09:00,601 TRACE [org.hibernate.event.def.AbstractFlushingEventListener] Flushing entities and processing referenced collections
2010-02-25 22:40:12,978 INFO  [org.hibernate.ejb.Ejb3Configuration] found EJB3 Entity bean: com.abc.AuditTrailEntry
...skipping...
2010-02-25 23:09:00,601 ERROR [org.hibernate.LazyInitializationException] failed to lazily initialize a collection of role: com.abc.entities...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.