[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6780) Wrong Query timeout calculation

Ruben Garcia (JIRA) noreply at atlassian.com
Thu Oct 27 15:14:22 EDT 2011


Wrong Query timeout calculation 
--------------------------------

                 Key: HHH-6780
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6780
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
    Affects Versions: 4.0.0.CR5, 4.0.0.CR4
         Environment: Hibernate 4.0.0.RC5, Spring 3.1.RC1
            Reporter: Ruben Garcia


Class: org.hibernate.engine.jdbc.internal.StatementPreparerImpl.StatementPreparationTemplate
Method: setStatementTimeout

private void setStatementTimeout(PreparedStatement preparedStatement) throws SQLException {
    if ( transactionTimeOut > 0 ) {
        int timeout = (int) ( transactionTimeOut - ( System.currentTimeMillis() / 1000 ) );
	if ( timeout <= 0 ) {
	    throw new TransactionException( "transaction timeout expired" );
        } else {
            preparedStatement.setQueryTimeout( timeout );
        }
    }
}

Test Code: 
Session session = openSession(); 
Transaction transaction = session.getTransaction();
transaction .setTimeout(20);


This calculation will be always negative:
int timeout = (int) ( transactionTimeOut - ( System.currentTimeMillis() / 1000 ) ); 

resulting TransactionException( "transaction timeout expired" ) will be throw.



--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list