-->
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.  [ 3 posts ] 
Author Message
 Post subject: detachedcriteria.createAlias not generating join
PostPosted: Tue Jul 21, 2009 8:58 am 
Newbie

Joined: Thu Jul 16, 2009 4:18 am
Posts: 3
I'm using detachedCriteria to create a correlated subquery. This all works fine until I try to add an alias to the detachedcriteria in which case hibernate adds the restriction, but does not add a join for the new aliased table. Unfortunately hibernate also don't throw any kind of exception to let me know what I'm doing wrong. Could someone please point me in the right direction

Code:
             DetachedCriteria subCriteria = DetachedCriteria.forClass(persistenceMapping.getClassToSave(),detachedAlias)
            .createAlias(detachedAlias + "." + "eventType", "ET1")
            .setProjection( Property.forName(detachedAlias + "." + attribute).max())
            .add( Property.forName(detachedAlias + "." + matchAttribute).eqProperty(mainCriteriaAlias + "." + matchAttribute) )
            .add(Restrictions.eq("ET1.eventTypeCode", "OPEN"));
           
           
           
            Criteria criteria = session.createCriteria(persistenceMapping.getClassToSave(),mainCriteriaAlias);                                   
            criteria.add(Subqueries.propertyEq(attribute, subCriteria));
           
            Map aliasMap = new HashMap();
            hibernateReflectionUtil.generateUniqueRestrictionsByVo(
                    session, criteria, persistenceMapping.getClassToSave(), restriction, false, true, aliasMap);
            if (join!=null)
               hibernateReflectionUtil.generateJoinRestrictionsByVo(session, persistenceMapping.getClassToSave(), join, criteria, false);
           
            String excludeAttName = excludeAttrib;
            int indexOf =excludeAttrib.indexOf(".");
            if (indexOf>-1){
               excludeAttName = (String) aliasMap.get(excludeAttrib.substring(0,indexOf));
               excludeAttName += "." + excludeAttrib.substring(indexOf+1);
            }
           
            criteria.add(Restrictions.not(Restrictions.in(excludeAttName, excludeList)));
            list = criteria.list();                       


resultant sql
Code:
select
    this_.ACC_EVENT_ID as ACC1_4_5_,
    this_.ROW_TOUCHED_DATETIME as ROW2_4_5_,
    this_.EVENT_PTY_ID as EVENT3_4_5_,
    this_.ACC_ID as ACC4_4_5_,
    this_.ACTUAL_EVENT_DT as ACTUAL5_4_5_,
    this_.ACTUAL_EVENT_DT_GRANULARITY as ACTUAL6_4_5_,
    this_.EXPECTED_EVENT_DT as EXPECTED7_4_5_,
    this_.EXPECTED_EVENT_DT_GRANULARITY as EXPECTED8_4_5_,
    this_.EVENT_TYPE_ID as EVENT9_4_5_,
    alias3x1_.EVENT_TYPE_ID as EVENT1_14_3_,
    alias3x1_.EVENT_TYPE_CODE as EVENT2_14_3_,
    alias3x1_.EVENT_TYPE_NAME as EVENT3_14_3_,
    alias3x1_.EVENT_TYPE_DESC as EVENT4_14_3_,
    alias3x1_.ROW_STATUS_IND as ROW5_14_3_,
    alias3x1_.SCHEME_ID as SCHEME6_14_3_,
    alias4x2_.SCHEME_ID as SCHEME1_11_4_,
    alias4x2_.PARENT_SCHEME_ID as PARENT2_11_4_,
    alias4x2_.IMMUTABLE_MEMBERS_FLAG as IMMUTABLE3_11_4_,
    alias4x2_.MULT_MEMBERS_ALLOWED_FLAG as MULT4_11_4_,
    alias4x2_.SCHEME_DESC as SCHEME5_11_4_,
    alias4x2_.SCHEME_NAME as SCHEME6_11_4_,
    alias4x2_.SCHEME_CODE as SCHEME7_11_4_
from
    ACCOUNT_EVENT this_
inner join
    EVENT_TYPE alias3x1_
        on this_.EVENT_TYPE_ID=alias3x1_.EVENT_TYPE_ID
inner join
    SCHEME alias4x2_
        on alias3x1_.SCHEME_ID=alias4x2_.SCHEME_ID
where
    this_.ACTUAL_EVENT_DT = (
        select
            max(this0__.ACTUAL_EVENT_DT) as y0_
        from
            ACCOUNT_EVENT this0__
        where
            this0__.ACC_ID=this_.ACC_ID
            and et1x1_.EVENT_TYPE_CODE=?
    )
    and alias4x2_.SCHEME_ID=?
    and not alias3x1_.EVENT_TYPE_CODE in (
        ?, ?, ?
    )


Top
 Profile  
 
 Post subject: Re: detachedcriteria.createAlias not generating join
PostPosted: Sat Aug 08, 2009 3:48 am 
Newbie

Joined: Sat Aug 08, 2009 3:44 am
Posts: 1
Same problem here. Have you found any solution for this?
Thanks


Top
 Profile  
 
 Post subject: Re: detachedcriteria.createAlias not generating join
PostPosted: Mon Aug 10, 2009 2:10 am 
Newbie

Joined: Mon Aug 10, 2009 2:06 am
Posts: 1
This is the exact issue I am having as well. If a solution is found, please respond.


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