-->
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: I need to eliminate cross joins in hibernate generated query
PostPosted: Wed May 30, 2012 11:38 am 
Newbie

Joined: Wed Sep 10, 2008 1:01 pm
Posts: 6
Hibernate versions used:
    hibernate-annotations 3.5.5-Final
    hibernate-commons-annotations 3.2.0.Final
    hibernate-jpa-2.0-api 1.0.0.Final
    Java 1.6.028

Java version used: 1.6.028
[/code]

*Hibernate Query*
Code:
       hql.append("FROM TBucket t1 JOIN FETCH t1.prd JOIN FETCH t1.psAct ");
   

*Configuration*
Code:
       TBucket
       @Table (name = "f_t_bucket")
      
             @ManyToOne (cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, targetEntity = Posprd.class)
             @JoinColumns({
                 @JoinColumn(name = "dev_key", referencedColumnName="dev_key"),
                 @JoinColumn(name = "dev_cycle_key", referencedColumnName="cycle_key"),
             })
            
             public IPosprd getprd() {
             return prd;
             }
            
   prd (
      
       @Table (name = "snp_prd")
       public class Posprd implements IPosprd {
      
          @Id
          private PrdPk PrdPk;
          
          public PrdPk getPrdPk() {
             return PrdPk;
          }
          
      }
      
      PrdPk
                
      @Column (name = "dev_key")
      private Long PrdKey;

      @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
      @JoinColumn(name = "cycle_key", nullable = false)
      private Cycle cycle;



   Cycle

      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cycle_sequence")
      @Column (name = "cycle_key", nullable = false)
      public Long getId() {
         return id;
      }

      
   )
            
      
             @ManyToOne (cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, targetEntity = Pospsact.class)
             @JoinColumn (name = "ps_act_key", nullable = false)
             public IPospsact getpsact() {
                   return psAct;
             }     
            
       psAct (
          @Table (name = "ps_act")
          public class PosPsact implements IPospsact {
              @Id
          @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "act_sequence")
         @Column (name = "psn_act_key", nullable = false)
         public Long getId() {
       return id;
         }

       )
   

*Generating Query*
Code:
       FROM f_t_bucket tbucke0_
                INNER JOIN snp_prd posprd1_
                   ON tbucke0_.dev_cycle_key = posprd1_.cycle_key
                      AND tbucke0_.dev_key = posprd1_.dev_key
                         
               JOIN FETCH t1.psAct                   
                         
                INNER JOIN ps_act pospsn2_
                   ON tbucke0_.ps_act_key = pspsn2_.ps_act_key
                  
       CROSS JOIN snp_prd posprd3_
       where tbucke0_.dev_cycle_key=posprd3_.cycle_key and tbucke0_.dev_key=posprd3_.dev_key and tbucke0_.posn_act_key=pospsn5_.posn_act_key
   

As you can see from above hibernate is generating cross joins at the end. Why is that? How can I stop hibernate from generating those cross joins?

If I just use the hql like
Code:
       "FROM TBucket t1  ";
   

It is generating
Code:
       from f_t_bucket tbucke0_
       cross join snp_prd psprd1_
       where tbucke0_.dev_cycle_key=posprd3_.cycle_key and tbucke0_.dev_key=posprd3_.dev_key and tbucke0_.posn_act_key=pospsn5_.posn_act_key
   

How can I make it remove the "extra" cross join that I am getting at the end?


Top
 Profile  
 
 Post subject: Re: I need to eliminate cross joins in hibernate generated query
PostPosted: Wed May 30, 2012 4:37 pm 
Newbie

Joined: Wed Sep 10, 2008 1:01 pm
Posts: 6
the problem instead of using from TBucket t1 join t1.prd p and in Criteria, I should be using p.excgId in (?,?) I was using Criteria like t1.prd.excgId in (?,?). That is the reason why it was generating cross joins. I should be using the alias to do filtering.


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.