views:

1151

answers:

1

Hello Everyone,

I am having this serious problem in a web-app that is using a thread to listen on a port for packets and process those packets.

Processing of a packet involves database transactions, so basically it is like :


Thread:
run () {
  try {
    ...
    fireMessageEvent(data);
    ...
  } catch (Exception e) {
  }
}

fireMessageEvent(data) {
  someclass.messageArrived(data);
}

SomeClass:
messageArrived(Data data) {
  try {
    someOtherClass.setData(data);
  } catch (Exception e) {
  }
}

SomeOtherClass:
setData (Data data)
{
  try {
   ..
   processDataPart1(data);
   processDataPart2(data);
   ..
  } catch (Exception e) {
  }
}

processDataPart1(data)
{
    daolayer.getSomeObjectFromDatabase(x);
    ..
    daolayer.save(y);
    ..
    someotherDaolayer.update(a);
    ..
}

processDataPart2(data)
{
    daolayer.getSomeObjectFromDatabase(x);
    ..
    daolayer.save(y);
    ..
    someotherDaolayer.update(a);
    ..
    daolayer.save(b);
    ..
}


The problem is that I get an exception 'Transaction not sucessfully started'. Also interestingly the exception gets caught by the catch in the thread, and hence doesnot save the data (probably due to rollback.?.). For the moment, I create another dummy object to save in the database and then delete it, so that when the exception occurs its the dummy object that doesn't get saved and the previous objects do get saved.

Can anyone help on this? Has anyone encountered the same problem?

Here is the exception details:

2010-02-25 10:30:33,759 INFO [packetInfo log] - Could not commit Hibernate transaction; nested exception is org.hibernate.TransactionException: Transaction not successfully started
2010-02-25 10:30:33,759 INFO [packetInfo log] - org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:659)
2010-02-25 10:30:33,759 INFO [packetInfo log] - org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
2010-02-25 10:30:33,759 INFO [packetInfo log] - org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
2010-02-25 10:30:33,759 INFO [packetInfo log] - org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
2010-02-25 10:30:33,759 INFO [packetInfo log] - org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
2010-02-25 10:30:33,774 INFO [packetInfo log] - org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
2010-02-25 10:30:33,774 INFO [packetInfo log] - org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
2010-02-25 10:30:33,774 INFO [packetInfo log] - com.comp.projectx.service.lear.communicator.AriadneListenerServiceImplementation$$EnhancerByCGLIB$$e5054dfb.setData()
2010-02-25 10:30:33,774 INFO [packetInfo log] - com.comp.projectx.service.lear.communicator.PLCListenerServiceImplementation.messageArrived(PLCListenerServiceImplementation.java:153)
2010-02-25 10:30:33,774 INFO [packetInfo log] - com.comp.projectx.service.lear.communicator.Listener.fireMessageEvent(Listener.java:229)
2010-02-25 10:30:33,774 INFO [packetInfo log] - com.comp.projectx.service.lear.communicator.Listener.run(Listener.java:94)

Configuration in web.xml:

    hibernateFilter : org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    hibernateFilter url-pattern: *.95
    hibernateFilter url-pattern: /dwr/*
    lazyLoadingFilter: org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    lazyLoadingFilter url-pattern: /*

Hibernate Configuration:


    jee:jndi-lookup id="dataSource" jndi-name="/jdbc/kernstreamDS" resource-ref="true" expected-type="javax.sql.DataSource" 

    bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
        property name="dataSource" ref="dataSource" 
    bean

    bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"

In the Dao layer to save an object:


    getSession().saveOrUpdate(resultObj);

to retrieve:


    List resultObj = getSession().createCriteria(Lot.class)
            .add(Restrictions.eq("publicId", publicId)).list();

Any help would be greatly appreciated.

A: 

I solved the problem. In case anyone else had the same issue here is how I did it.

Basically, in the dao layer, it was using Spring transaction management and at other locations it was using hibernate transaction management. Mixing the two is not a good idea. So by changing in the dao layer from using

getSession().saveOrUpdate(...);

to

getHibernateTemplate().saveOrUpdate(...);

solved the issue.

Thank you all for the comments.

saky