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?