If one has an entity such as:
@Entity
@Table(name="main")
public class MainEntity {
private int id;
private Code1 code1;
private Code2 code2;
private Code3 code3;
@Id
public int getId(){return id;}
public void setId(int pId){id = pId;}
@ManyToOne(targetEntity=Code1.class)
@JoinColumn(name="code1")
public int getCode1(){return code1;}
public void setCode1(Code2 pCode1){code1 = pCode1;}
@ManyToOne(targetEntity=Code2.class)
@JoinColumn(name="code2")
public int getCode2(){return code2;}
public void setCode2(Code2 pCode2){code2 = pCode2;}
@ManyToOne(targetEntity=Code3.class)
@JoinColumn(name="code3")
public int getCode3(){return code3;}
public void setCode3(Code3 pCode3){code3 = pCode3;}
}
while Code1, Code2 and Code3 are simple code-desc entities (having only to simple properties, code and desc), it is expected that if one tries to fetch all the MainEntity objects (using "Select a From MainEntity a" query, for example) there will be only one sql-select statement
(
SELECT m.id, m.code1, m.code2, m.code3, c1.code, c1.desc, c2.code, c2.desc, c3.code, c3.desc
FROM main m
LEFT OUTER JOIN code1 c1 ON m.code1 = c1.code
LEFT OUTER JOIN code2 c2 ON m.code2 = c2.code
LEFT OUTER JOIN code3 c3 ON m.code3 = c3.code
)
Instead, there are 3*n+1 sql-select statements (where n is the number of rows in the main table). One from the main table, and for each row, one from each codes table.
If one uses a query from
SELECT a FROM MainEntity a JOIN FETCH a.code1 JOIN FETCH a.code2 JOIN FETCH a.code3
it works correctly, using one sql-statements.
Is this a bug? how should it be fixed?
Hibernate version:3.1.rc2
Name and version of the database you are using:Oracle9i
|