-->
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.  [ 8 posts ] 
Author Message
 Post subject: HQL query producing SQL with empty FROM clause
PostPosted: Fri Mar 21, 2014 12:27 pm 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
Hi,

I have the following HQL query:

Code:
SELECT
        DISTINCT co.mpsId
    FROM
        com.example.search.SearchCase co
    WHERE
        EXISTS (
           
        FROM
            co.g2s t0
        WHERE
            (
                EXISTS (
                    SELECT
                        sa
                    FROM
                        t0.g2Multi sa
                    WHERE
                        sa = :hp0
                )
            )


(the hp0 parameter would be set to a String value)

So, starting from the top, SearchCase has a list called 'g2s':

Code:
      <list name="g2s" lazy="true" cascade="all,delete-orphan">
         <key update="true">
            <column name="`SEARCHCASE_G2S_MPSID`" not-null="false" unique="false"/>
         </key>
         <list-index column="`SEARCHCASE_G2S_IDX`"/>
         <one-to-many entity-name="com.example.search.Global2"/>
      </list>


As you can see, it's a list of Global2 objects. Global2 then contains a list of Strings called 'g2Multi':

Code:
      <list name="g2Multi" table="`MPS_1_SERCH_GLOBAL2G2MULTI`" lazy="true" cascade="all,delete-orphan">
         <key update="true">
            <column name="`GLOBAL2_G2MULTI_MPSID`" not-null="true" unique="false"/>
         </key>
         <list-index column="`GLOBAL2_G2MULTI_IDX`"/>
         <element type="java.lang.String" not-null="false" unique="false">
            <column not-null="false" unique="false" name="`G2MULTI`" length="400"/>
         </element>
      </list>


To summarize, SearchCase contains a list of Global2 objects ('g2s'); Each Global2 object contains a list of Strings ('g2Multi').

A problem occurs when this gets converted to SQL.
Notice the empty FROM clause ("from where") in the first sub-query:

Code:
select
            distinct searchcase0_.[MPS_ID] as col_0_0_
        from
            [MPS_1_SERCH_SEARCHCASE] searchcase0_
        where
            exists (
                select
                    g2s1_.[MPS_ID]
                from
                   
                where
                    searchcase0_.[MPS_ID]=g2s1_.[SEARCHCASE_G2S_MPSID]
                    and (
                        exists (
                            select
                                g2multi2_.[G2MULTI]
                            from
                                [MPS_1_SERCH_GLOBAL2G2MULTI] g2multi2_
                            where
                                g2s1_.[MPS_ID]=g2multi2_.[GLOBAL2_G2MULTI_MPSID]
                                and g2multi2_.[G2MULTI]=?
                        )
                    )
                )


Can anyone immediately spot why this is going wrong? If not, I can provide more details, but didn't want to write a huge post if the detail isn't necessary.

Many thanks for any help,
Ben.


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Mon Apr 07, 2014 12:34 pm 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
Any ideas at all?

Even if you can't explain Hibernate's behaviour, can you spot anything obviously odd about what I'm trying to achieve? Is there a better or more obvious way to get the result I need?

Thanks,
Ben.


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Fri May 09, 2014 5:29 am 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
Hi everyone,

I've raised a JIRA issue for this here:

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

Regards,
Ben.


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Tue May 20, 2014 9:14 am 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
I've made some progress investigating this and have observed behaviour I don't understand in a class called FromElementFactory.

Please take a look at the comment I've added to the JIRA:

https://hibernate.atlassian.net/browse/HHH-9121?focusedCommentId=61072&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-61072


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Thu May 22, 2014 5:24 am 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
gabylis wrote:
I can provide more details, but didn't want to write a huge post if the detail isn't necessary....z


I'm not sure what you're getting at, but I've actually attached a project to the JIRA entry that allows the problem to be reproduced.

Regards,
Ben.


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Tue Mar 24, 2015 10:53 am 
Newbie

Joined: Fri Mar 21, 2014 11:59 am
Posts: 8
Hi all,

If anyone is able to offer any help with this, I've still not solved this one.

Many thanks,
Ben.


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Tue Mar 24, 2015 5:06 pm 
Newbie

Joined: Sat Mar 14, 2015 8:54 am
Posts: 4
Hi, Benjamin.

I will take a look at it tomorrow, will contact you as soon as I get any update.
Thanks!


Top
 Profile  
 
 Post subject: Re: HQL query producing SQL with empty FROM clause
PostPosted: Thu Mar 26, 2015 2:32 pm 
Newbie

Joined: Sat Mar 14, 2015 8:54 am
Posts: 4
Hi, all.
I have updated issue HHH-9121 comments.


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

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.