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,