-->
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.  [ 1 post ] 
Author Message
 Post subject: Listeners conflict issue:transaction's readOnly=false ignore
PostPosted: Mon Jul 19, 2010 4:34 pm 
Beginner
Beginner

Joined: Thu Jun 24, 2010 2:30 am
Posts: 23
We have customer AuditTrail listener defined in hibernate.config.xml. I try to run test thet inserts a lot of records into some DB table and if AuditTrail listeners enabled an exception is thrown. If I disable listeners no exception occured. However, the exception's stacktrace doesn't contains AuditTrail classes. And another strange thing the exception reports about trying to write during readonly transaction, although transaction marked with readonly=false. How I can check where is the problem?

P.S. I know that can be transaction problem, so I'll also ask it in spring forum.
Stacktrace:
Code:
2010-07-19 23:19:27,609 INFO  (                  Version.java:40)     - Hibernate Search 3.2.0.Final
2010-07-19 23:19:27,609 INFO  (                  Version.java:40)     - Hibernate Search 3.2.0.Final
Start test: Mon Jul 19 23:19:35 IDT 2010
Exception in thread "main" org.springframework.transaction.UnexpectedRollbackException: Transaction rolled back because it has been marked as rollback-only
   at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:717)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:412)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy48.createAndSave(Unknown Source)
   at com.mycompany.test.TestSearchIndex.main(TestSearchIndex.java:33)


Test class:
Code:
public class TestSearchIndex {
   public static void main( String[] args ) {
      ApplicationContext ctx =
         new ClassPathXmlApplicationContext( "applicationContext.xml" );            
      TestSpotOrderService service =
         (TestSpotOrderService)ctx.getBean( "testSpotOrderService" );
      Date date = new Date(), startDate = new Date(), date2;      
30      System.out.println( "Start test: " + date );
31      int result = 0;
32      for( int i = 0; i < 2000; i++ ) {         
33         result += service.createAndSave();
34         date2 = new Date();
35         long elapsed = ( date2.getTime() - date.getTime() ) / 1000;
36         long mins =
37             ( date2.getTime() - startDate.getTime() ) % 3600000 / 60000;
38         long hrs =
39            ( date2.getTime() - startDate.getTime() ) / 3600000;
40         System.out.println(
            result + " records added. Time elapsed: " +   elapsed + "sec." +
            " Time from start: " + hrs + "h " + mins + "min" );
         date = date2;
      }
      System.out.println(
         "Test end. " + result + " records were added. " + new Date() );
      
   }   

}


Create method:
Code:
public class TestSpotOrderServiceImpl implements TestSpotOrderService {
   private static final Logger LOG =
      Logger.getLogger( TestSpotOrderServiceImpl.class );
   
   private MutableDAO<Company> companyDAO;   
   private MutableDAO<SpotOrder> spotOrderDAO;
   
   @Transactional( readOnly = false, propagation = Propagation.REQUIRES_NEW)
   public int createAndSave() {
      Company[] allCompanies = companyDAO.findAll().toArray( new Company[0] );
      SpotOrder entity;
      StringBuffer currName;
      Random generator = new Random();
      LOG.debug(
         "Starting to add 10,000 spotOrder records with random values. "  );
      int result = 0;
      for( int i = 0; i < 50000; i++ ) {         
         try {
            entity = new SpotOrder();
            entity.setCompany(
               allCompanies[ generator.nextInt( allCompanies.length ) ] );
            
            currName = new StringBuffer();
            for( int j = 0; j < 45; j++ ) {
               currName.append( (char)( 'A' + generator.nextInt( 26 ) ) );
            }
            entity.setName( currName.toString() );
            spotOrderDAO.create( entity );
            result++;
         } catch( Exception e ) {         
            LOG.info( "Exception during spots order test:", e );         
         }
      }
      LOG.debug(
         ( result > 0 ? "Success" : "Error" ) +
         " adding 10,000 spotOrder records with random values. " );
      return result;
   }

.......
}


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

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.