-->
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.  [ 2 posts ] 
Author Message
 Post subject: Projections.id() may return column from wrong entity table
PostPosted: Thu May 02, 2013 8:44 pm 
Newbie

Joined: Thu May 02, 2013 6:40 pm
Posts: 2
Hello everybody,

I'm seeing this behavior in Hibernate 3.6.5, there seems to be some strange behavior around Projections.id(). If I run the code below to query the DeterminantDefinition table I see the correct query below getting generated by Hibernate.


Code:
   DetachedCriteria crit = this.getDetachedCriteria();
//   crit.setProjection(Projections.id());
   return crit.getExecutableCriteria(session);

17:26:20,232 INFO  [STDOUT] Hibernate:
    select
        *
    from
        ( /* criteria query */ select
            this_.id as id9_9_,
            this_.effectiveDate as effectiv2_9_9_,
            this_.terminationDate as terminat3_9_9_,
            this_.alwaysExecute as alwaysEx4_9_9_,
            this_.approvalActionCfgId as approval7_9_9_,
            this_.defaultAggregationType as defaultA5_9_9_,
            this_.depActionCfgId as depActio8_9_9_,
            this_.determinant_id as determin9_9_9_,
            this_.immutable as immutable9_9_,
            this_.shadowDeterminant_id as shadowD10_9_9_,
            this_.storeAdaoterCfgId as storeAd11_9_9_,
            this_.streamBuilderCfgId as streamB12_9_9_,
            this_2_.frequencyUnitType as frequenc1_21_9_,
            this_2_.intervalDuration as interval2_21_9_,
            this_2_.inputSourceConfiguration_id as inputSou4_21_9_,
            case
                when this_1_.id is not null then 1
                when this_2_.id is not null then 2
                when this_.id is not null then 0
            end as clazz_9_,
            approvalac4_.id as id5_0_,
            approvalac4_.beanId as beanId5_0_,
            parameters5_.cfgId as cfgId5_11_,
            parameters5_.id as id11_,
            parameters5_.id as id1_1_,
            parameters5_.elementType as elementT2_1_1_,
            parameters5_.name as name1_1_,
            parameters5_.serializedValue as serializ4_1_1_,
            parameters5_.type as type1_1_,
            parameters5_.cfgId as cfgId1_1_,
            dependency6_.id as id6_2_,
            dependency6_.beanId as beanId6_2_,
            determinan1_.id as id14_3_,
            determinan1_1_.createdDate as createdD2_14_3_,
            determinan1_1_.lastUpdatedBy as lastUpda3_14_3_,
            determinan1_1_.lastUpdatedDate as lastUpda4_14_3_,
            determinan1_1_.naturalKeyUpdates as naturalK5_14_3_,
            determinan1_1_.name as name14_3_,
            determinan1_.dataType as dataType15_3_,
            parentgrou8_.determinants_id as determin2_14_,
            group2_.id as parentGr1_,
            group2_.id as id14_4_,
            group2_1_.createdDate as createdD2_14_4_,
            group2_1_.lastUpdatedBy as lastUpda3_14_4_,
            group2_1_.lastUpdatedDate as lastUpda4_14_4_,
            group2_1_.naturalKeyUpdates as naturalK5_14_4_,
            group2_1_.name as name14_4_,
            group2_.description as descript1_18_4_,
            determinan10_.id as id14_5_,
            determinan10_1_.createdDate as createdD2_14_5_,
            determinan10_1_.lastUpdatedBy as lastUpda3_14_5_,
            determinan10_1_.lastUpdatedDate as lastUpda4_14_5_,
            determinan10_1_.naturalKeyUpdates as naturalK5_14_5_,
            determinan10_1_.name as name14_5_,
            determinan10_.dataType as dataType15_5_,
            storeadapt11_.id as id8_6_,
            storeadapt11_.beanId as beanId8_6_,
            streambuil12_.id as id7_7_,
            streambuil12_.beanId as beanId7_7_,
            inputsourc13_.id as id19_8_,
            inputsourc13_.beanId as beanId19_8_,
            inputsourc13_.incremental as incremen3_19_8_,
            inputsourc13_.sourceTimeZone as sourceTi4_19_8_
        from
            DeterminantDefinition this_
        left outer join
            DerivedDeterminant this_1_
                on this_.id=this_1_.id
        left outer join
            PrimaryDeterminant this_2_
                on this_.id=this_2_.id
        left outer join
            ApprovalActionCfg approvalac4_
                on this_.approvalActionCfgId=approvalac4_.id
        left outer join
            ApprovalActionParameter parameters5_
                on approvalac4_.id=parameters5_.cfgId
        left outer join
            DependencyActionCfg dependency6_
                on this_.depActionCfgId=dependency6_.id
        inner join
            Determinant determinan1_
                on this_.determinant_id=determinan1_.id
        left outer join
            DerivableObject determinan1_1_
                on determinan1_.id=determinan1_1_.id
        inner join
            ModelGroup_Determinant parentgrou8_
                on determinan1_.id=parentgrou8_.determinants_id
        inner join
            ModelGroup group2_
                on parentgrou8_.parentGroups_id=group2_.id
        left outer join
            DerivableObject group2_1_
                on group2_.id=group2_1_.id
        left outer join
            Determinant determinan10_
                on this_.shadowDeterminant_id=determinan10_.id
        left outer join
            DerivableObject determinan10_1_
                on determinan10_.id=determinan10_1_.id
        left outer join
            StoreAdapterConfig storeadapt11_
                on this_.storeAdaoterCfgId=storeadapt11_.id
        left outer join
            StreamBuilderConfig streambuil12_
                on this_.streamBuilderCfgId=streambuil12_.id
        left outer join
            InputSourceConfiguration inputsourc13_
                on this_2_.inputSourceConfiguration_id=inputsourc13_.id
        where
            (
                group2_1_.name=?
                or group2_1_.name=?
                or group2_1_.name=?
                ...
                or group2_1_.name=?
            )
            and this_.effectiveDate<?
            and this_.terminationDate>=?
        order by
            determinan1_1_.name asc,
            determinan1_1_.name asc )
    where
        rownum <= ?

If I uncomment the line that sets the Projections.id(), the SQL query statement that is generated (please see below) gets the "id" field from the joined Determinant table instead of the DeterminantDefinition table. Can someone please suggest a workaround that I can use? I've already tried Property.fromName and had the identical effect.

Thank you, eugen


Code:
13:26:28,883 INFO  [STDOUT] Hibernate:
    select
        *
    from
        ( /* criteria query */ select
            determinan1_.id as y0_
        from
            DeterminantDefinition this_
        left outer join
            DerivedDeterminant this_1_
                on this_.id=this_1_.id
        left outer join
            PrimaryDeterminant this_2_
                on this_.id=this_2_.id
        inner join
            Determinant determinan1_
                on this_.determinant_id=determinan1_.id
        left outer join
            DerivableObject determinan1_1_
                on determinan1_.id=determinan1_1_.id
        inner join
           ModelGroup_Determinant parentgrou5_
                on determinan1_.id=parentgrou5_.determinants_id
        inner join
            ModelGroup group2_
                on parentgrou5_.parentGroups_id=group2_.id
        left outer join
            DerivableObject group2_1_
                on group2_.id=group2_1_.id
        where
            (
                group2_1_.name=?
                or group2_1_.name=?
                ...
                or group2_1_.name=?
            )
            and this_.effectiveDate<?
            and this_.terminationDate>=?
        order by
            determinan1_1_.name asc,
            determinan1_1_.name asc )
    where
        rownum <= ?


Top
 Profile  
 
 Post subject: Re: Projections.id() may return column from wrong entity table
PostPosted: Fri May 03, 2013 7:28 pm 
Newbie

Joined: Thu May 02, 2013 6:40 pm
Posts: 2
It turns out that the query as it was were OK, it was the code below higher up in the callstack that was messing it up somehow.

Code:
   Criteria crit = getCriteria(session);
   crit.setProjection(Projections.rowCount());
   Long size = ((Long)crit.uniqueResult());


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.