-->
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.  [ 1 post ] 
Author Message
 Post subject: Question in Criteria Query
PostPosted: Sat Jul 12, 2008 9:56 pm 
Newbie

Joined: Sun Jul 06, 2008 9:32 pm
Posts: 6
Hello,

Could any one please help, I referred so many articles but don't get information. I have question in my below Criteria query:-

Code:
      List<?> menuGroups = HibernateUtil.getSession().createCriteria(Menugroup.class).
      add( Restrictions.eq("published", true)).addOrder( Property.forName("name").asc()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).
      setFetchMode("catgroups", FetchMode.JOIN).
      createCriteria("catgroups").addOrder( Property.forName("name").asc()).
      add( Restrictions.eq("published", true) ).setFetchMode("dealitems", FetchMode.DEFAULT)
      .list();


When you closely look at the query, the association is, Menugroups--(1 to many)-->Catgroups---(1 to many)---> Dealitems. I have configured lazy fetching and have set up batch-size=10 in config file.

When the above query is fired, hibernate generates the below sqls,
Code:
Hibernate:
    select
        this_.MENUGROUP_ID as MENUGROUP1_0_1_,
        this_.NAME as NAME0_1_,
        this_.DESCRIPTION as DESCRIPT3_0_1_,
        this_.PUBLISHED as PUBLISHED0_1_,
        this_.LASTUPDATE as LASTUPDATE0_1_,
        catgroup1_.CATGROUP_ID as CATGROUP1_1_0_,
        catgroup1_.MENUGROUP_ID as MENUGROUP2_1_0_,
        catgroup1_.NAME as NAME1_0_,
        catgroup1_.DESCRIPTION as DESCRIPT4_1_0_,
        catgroup1_.IMGURL as IMGURL1_0_,
        catgroup1_.PUBLISHED as PUBLISHED1_0_,
        catgroup1_.SUGESSTION as SUGESSTION1_0_,
        catgroup1_.LASTUPDATE as LASTUPDATE1_0_
    from
        cyddev.MENUGROUP this_
    inner join
        cyddev.CATGROUP catgroup1_
            on this_.MENUGROUP_ID=catgroup1_.MENUGROUP_ID
    where
        this_.PUBLISHED=?
        and catgroup1_.PUBLISHED=?
    order by
        this_.NAME asc,
        catgroup1_.NAME asc
Hibernate:
    select
        catgroups0_.MENUGROUP_ID as MENUGROUP2_1_,
        catgroups0_.CATGROUP_ID as CATGROUP1_1_,
        catgroups0_.CATGROUP_ID as CATGROUP1_1_0_,
        catgroups0_.MENUGROUP_ID as MENUGROUP2_1_0_,
        catgroups0_.NAME as NAME1_0_,
        catgroups0_.DESCRIPTION as DESCRIPT4_1_0_,
        catgroups0_.IMGURL as IMGURL1_0_,
        catgroups0_.PUBLISHED as PUBLISHED1_0_,
        catgroups0_.SUGESSTION as SUGESSTION1_0_,
        catgroups0_.LASTUPDATE as LASTUPDATE1_0_
    from
        cyddev.CATGROUP catgroups0_
    where
        catgroups0_.MENUGROUP_ID in (
            ?, ?, ?
        )



My issue here is, the one of the criteria restriction published=true is not applied in the 2nd SQLs. So I am getting unpublished catgroups in the result. Could any one help please what is wrong in my Criteria query and what needs to be added more ?

Reply is appreciated.

Thanks
Sarav.


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

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.