Bug 1508697

Summary: Hibernate SQLQuery#executeUpdate() does not invoke Statement#setQueryTimeout()
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Masafumi Miura <mmiura>
Component: HibernateAssignee: Gail Badner <gbadner>
Status: CLOSED EOL QA Contact: Pavel Slavicek <pslavice>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.4.17CC: gbadner, msimka, smarlow
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-08-19 12:44:14 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
hibernate-reproducer.zip
none
a proposed patch for NativeSQLQueryPlan none

Description Masafumi Miura 2017-11-02 00:58:28 UTC
Created attachment 1346823 [details]
hibernate-reproducer.zip

### Description of problem:

Hibernate org.hibernate.SQLQuery#executeUpdate() does not invoke java.sql.Statement#setQueryTimeout() even if SQLQuery#setTimeout() is specified.

Note that org.hibernate.SQLQuery#list() and org.hibernate.Query#executeUpdate() works fine but org.hibernate.SQLQuery#executeUpdate() does not work.


### Version-Release number of selected component (if applicable):

EAP 6.4 CP17 (Hibernate 4.2.27.Final)


### How reproducible:

Anytime


### Steps to Reproduce:

1. Enable spy log:

    /subsystem=logging/logger=jboss.jdbc.spy:add
    /subsystem=logging/logger=jboss.jdbc.spy:write-attribute(name="level", value="TRACE")

2. Build and deploy the attached reproducer, which is based on EAP 6 quickstarts hibernate4.

    mvn clean package jboss-as:deploy

3. Access the web-app 

  1) test.SelectServlet, which specifies SQLQuery.setTimeout(5) then execute SQLQuery.list():

    curl http://localhost:8080/jboss-hibernate4/SelectServlet

  2) test.UpdateServlet, which specifies SQLQuery.setTimeout(5) and execute SQLQuery.executeUpdate():

    curl http://localhost:8080/jboss-hibernate4/UpdateServlet

  3) test.UpdateServlet2, which specifies Query.setTimeout(5) and execute Query.executeUpdate():

    curl http://localhost:8080/jboss-hibernate4/UpdateServlet2


### Actual results:

spy logging shows that Statement#setQueryTimeout() is not invoked in UpdateServlet although it's invoked in SelectServlet and UpdateServlet2. (You can confirm it with the spy log message "[Statement] setQueryTimeout(xxx)"). For example:

1) spy log for test.SelectServlet

INFO  [stdout] (http-/127.0.0.1:8080-1) start SelectServlet
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [DataSource] getConnection()
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [Connection] prepareStatement(select * from MemberHibernate4Demo)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [Statement] setQueryTimeout(5)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [PreparedStatement] executeQuery()
...(snip)...
INFO  [stdout] (http-/127.0.0.1:8080-1) end SelectServlet

2) spy log for test.UpdateServlet

INFO  [stdout] (http-/127.0.0.1:8080-1) start UpdateServlet
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [DataSource] getConnection()
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [Connection] prepareStatement(update MemberHibernate4Demo set name=? where id=0)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [PreparedStatement] setString(1, redhat)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [PreparedStatement] executeUpdate()
...(snip)...
INFO  [stdout] (http-/127.0.0.1:8080-1) end UpdateServlet

3) spy log for test.UpdateServlet2

INFO  [stdout] (http-/127.0.0.1:8080-1) start UpdateServlet2
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [DataSource] getConnection()
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [Connection] prepareStatement(update MemberHibernate4Demo set name=? where id=0)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [PreparedStatement] setString(1, redhat2)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [Statement] setQueryTimeout(5)
DEBUG [jboss.jdbc.spy] (http-/127.0.0.1:8080-1) java:jboss/datasources/Hibernate4QuickstartDS [PreparedStatement] executeUpdate()
...(snip)...
INFO  [stdout] (http-/127.0.0.1:8080-1) end UpdateServlet2


### Expected results:

Statement#setQueryTimeout() should also be invoked for SQLQuery#executeUpdate() in test.UpdateServlet.


### Additional info:

It looks org.hibernate.engine.query.spi.NativeSQLQueryPlan#performExecuteUpdate() misses calling "Statement#setQueryTimeout().

Comment 1 Masafumi Miura 2017-11-02 01:00:41 UTC
Created attachment 1346824 [details]
a proposed patch for NativeSQLQueryPlan

It looks org.hibernate.engine.query.spi.NativeSQLQueryPlan#performExecuteUpdate() misses calling "Statement#setQueryTimeout(). I attached a possible proposed patch for this.

Comment 2 Masafumi Miura 2017-11-02 08:30:22 UTC
Same issue exists in EAP 7.x, so the following JBEAP JIRAs are opened:

 - 7.1.z: https://issues.jboss.org/browse/JBEAP-13683
 - 7.0.z: https://issues.jboss.org/browse/JBEAP-13684

Also Hibernate JIRA is opened:

 - https://hibernate.atlassian.net/browse/HHH-12075