-->
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: How to Disable JOIN on subcalsses
PostPosted: Tue Oct 05, 2010 1:37 pm 
Newbie

Joined: Thu Jun 03, 2010 5:02 pm
Posts: 5
Hi,
I got a problem to disable the outer join on the subclass when joining the super class. I have a super class:
Code:
@Entity
@Table(name="table_1")
@Inheritance(strategy=InheritanceType.JOINED)
@IdClass(MyPK.class)

public class MySuperClazz implements Serializable
{
  @Id
  @Column(name = "id")
  @GenericGenerator(
      name = "IdSeq",
      strategy = "com.company.hibernate.VarcharSequenceGenerator",
      parameters = { @Parameter(name = "sequence", value = "TABLE1_SEQ") })
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
  private String id;

  @Id
  @Column(name = "type")
  private String type;
 
  .....
}

public class MyPK implements Serializable
{
   private static final long serialVersionUID = 1L;

   private String id; 
   private String type;
   
   public MyPK() {}

   public MyPK(String type, String id)
   {
     this.type = type;
     this.id = id;
    }

   public int hashCode() { ....  }
   public boolean equals(Object obj)  { .... }
}

And a sub class extending this super class:
Code:
@Entity
@Table(name="table_2")
@PrimaryKeyJoinColumns(
    {
   @PrimaryKeyJoinColumn(name="id"),
   @PrimaryKeyJoinColumn(name="type")
    })
public class MySubClazz extends MySuperClazz
{
  public MySubClazz()
  { super(); }

   .....
}

This is the object that I need to query:
Code:
@Entity
@Table(name="information")
@IdClass(InformationPK.class)
public class Information implements  Serializable
{
   @Id
   @Column(name = "information_id")
   @GenericGenerator(
      name = "IdSeq",
      strategy = "com.company.hibernate.VarcharSequenceGenerator",
      parameters = { @Parameter(name = "sequence", value = "INFORMATION_SEQ") })
   @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
   private String informationId;
   
   @Id
   @Column(name = "info_type")
   private String infoType;
   
   @ManyToMany
   @JoinTable(name = "info_item_content",
      joinColumns =
      {
              @JoinColumn(name="information_id", referencedColumnName="information_id"),
         @JoinColumn(name="info_type", referencedColumnName="info_type")
      },
      inverseJoinColumns =
      {
              @JoinColumn(name="id", referencedColumnName="id"),
         @JoinColumn(name="type", referencedColumnName="type")
     })
  private Set<MySuperClazz> superClazz;

  ........
}

I wrote the following query:
Code:
session.createCriteria(Information.class)
           .setFetchMode("superClazz", FetchMode.JOIN)
           .add(Restrictions.eq("informationId", "123456"))
           .list();

The generated oracle sql joined not only "MySuperClazz" but also the "MySubClazz" but I don't want the subclass to be joined as it is not necessary in this case and it slowed down the query as well.

Does any body know how to disable the join on the subclass?


Thanks,


Top
 Profile  
 
 Post subject: Re: How to Disable JOIN on subcalsses
PostPosted: Wed Oct 06, 2010 4:09 pm 
Beginner
Beginner

Joined: Mon Mar 02, 2009 3:36 pm
Posts: 25
while preparing the SQL from Criteria Query hibernate doesn't know that the object with "informationId" "123456" is the instance of which subclass so hibernate prepares the SQL to join all the subclasses of the Parent class . I mean to say whenever you will try to fetch the parent class it will join all its sub class.

Thanks,
Ganesh


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.