Search code examples
mysqldatabasehibernatesqlexception

MySQL error from a named query


I have a simple named query . We did an upgrade of hibernate libraries and we are seeing the following error . It was working fine in previous version.

Any reason why simple query fails like this ?

    Caused by: org.hibernate.exception.GenericJDBCException: could not execute query
        at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) [hibernate3.jar:]
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) [hibernate3.jar:]
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [hibernate3.jar:]
        at org.hibernate.loader.Loader.doList(Loader.java:2545) [hibernate3.jar:]
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [hibernate3.jar:]
        at org.hibernate.loader.Loader.list(Loader.java:2271) [hibernate3.jar:]
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459) [hibernate3.jar:]
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365) [hibernate3.jar:]
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate3.jar:]
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) [hibernate3.jar:]
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) [hibernate3.jar:]
        at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) [hibernate3.jar:]
        ... 157 more
Caused by: java.sql.SQLException: java.lang.IllegalArgumentException: Negative delay

Hibernate version is 3 and the code is like below

String selectSql = "select m from UserEntity m";
try {
    Query query = entityManager.createQuery(selectSql);
    Collection<UserEntity> userentities = (Collection<UserEntity>) query.getResultList();

}...


Solution

  • I am encountering the same "Negative delay" exception. Based on my investigation so far, it appears to be due to the JCA layer passing Integer.MAX_VALUE as a query timeout to the MySQL driver. The MySQL driver later mutiplies this by 1000 to convert it into milliseconds, which overflows into a negative value and triggers the "Negative delay" exception when used as a parameter for a java.util.Timer schedule() call. I'm not sure why JBoss is using Integer.MAX_VALUE in the particular scenario where this problem occurs, since I have specified an explicit timeout in the datasource XML configuration. One thing to note is that this problem is only observed after a slave node joins the JBoss cluster. Before that, when only the master node is running, the same workflow that invokes the query completes successfully.