Bug 1207637

Summary: [GSS](6.4.z) HHH-9758 - Broken SQL generated for dynamic batch fetching entities with a composite ID
Product: [JBoss] JBoss Enterprise Application Platform 6 Reporter: Fedor Gavrilov <fgavrilo>
Component: HibernateAssignee: Gail Badner <gbadner>
Status: CLOSED CURRENTRELEASE QA Contact: Martin Simka <msimka>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.3.3CC: bmaxwell, cdewolf, istudens, jmartisk, msimka, sfikes, smarlow
Target Milestone: CR1Keywords: Reopened
Target Release: EAP 6.4.3   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 1232406 (view as bug list) Environment:
Last Closed: 2017-01-17 10:36:35 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:
Bug Depends On:    
Bug Blocks: 1231259, 1232160, 1232406    
Attachments:
Description Flags
arquillian reproducer
none
Test case none

Description Fedor Gavrilov 2015-03-31 11:51:34 UTC
Created attachment 1008974 [details]
arquillian reproducer

Description of problem:


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


How reproducible:
Originally appeared with Oracle dialect, however issue is reproducible with any dialect that returns true on supportsRowValueConstructorSyntaxInInList() call. The issue appears if batch style is set to DYNAMIC mode, but never if LEGACY.

Steps to Reproduce:
Please see attached reproducer

Actual results:
org.h2.jdbc.JdbcSQLException : Syntax error in SQL statement "SELECT B0_.IDPART1 AS IDPART1_1_0_, B0_.IDPART2 AS IDPART2_1_0_, B0_.OTHERPROPERTY AS OTHERPRO3_1_0_ FROM B B0_ WHERE (B0_.IDPART1,B0_.IDPART2) IN ((?,?,(?,?) "; expected "[, ::, *, /, %, +, -, ||, ~, !~, NOT, LIKE, REGEXP, IS, IN, BETWEEN, AND, OR, ,, )"; SQL statement:
select b0_.idPart1 as idPart1_1_0_, b0_.idPart2 as idPart2_1_0_, b0_.otherProperty as otherPro3_1_0_ from B b0_ where (b0_.idPart1,b0_.idPart2) in ((?,?,(?,?) [42001-168] [Proxied because : Original exception not deserilizable, ClassNotFoundException] or similar, depending on dialect used

Expected results:
legal {dynamic batch} SQL getting generated

Additional info:

Comment 1 Gail Badner 2015-04-02 23:51:37 UTC
Created attachment 1010378 [details]
Test case

I cannot reproduce any problem using Oracle.

I'm attaching a patch for test case that will add a test to the hibernate-core unit tests. 

If you can update this test case to reproduce your issue, I'll take another look.

Comment 2 Gail Badner 2015-04-08 20:01:57 UTC
It's been almost a week. I will assume this is not a bug since I can't reproduce it. Re-open if you are able to reproduce.

Comment 4 Fedor Gavrilov 2015-04-15 07:23:30 UTC
Thye say they sue org.hibernate.dialect.Oracle10gDialect with Oracle 11g. But is should it also be reproducible H2 with the slightly modified dialect: it's only this change

 public class CustomH2Dialect
        extends H2Dialect {

    @Override
    public boolean supportsRowValueConstructorSyntaxInInList() {
        return true;
    }
}

Comment 5 Gail Badner 2015-04-15 18:21:42 UTC
H2 does not support this syntax, so it is obvious that changing supportsRowValueConstructorSyntaxInInList() to return true will fail.

Comment 12 Gail Badner 2015-04-29 22:32:36 UTC
Batch fetching entities that have a composite ID using BatchFetchStyle.DYNAMIC is broken. The generated SQL depends on whether Dialect.supportsRowValueConstructorSyntaxInInList() returns true or false, but it turns out that the SQL will be broken in both cases if the entity has a composite ID.

Hibernate jira issue: https://hibernate.atlassian.net/browse/HHH-9758

Comment 13 Gail Badner 2015-04-30 00:22:46 UTC
I've pushed the fix for HHH-9758 to 4.2 branch: https://github.com/hibernate/hibernate-orm/commit/503fe45c467c1dca21ced0196c1b69f17b54891d

Comment 21 Jan Martiska 2015-07-29 13:17:16 UTC
Verified in EAP 6.4.3.CR1.

Comment 22 Petr Penicka 2017-01-17 10:36:35 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.

Comment 23 Petr Penicka 2017-01-17 10:37:25 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.