With the following entities:
@Entity
@table(name="a")
public class A {
private int id;
private List<B> bs;
@Id
public int getId() {return id;}
public void setId(int pId){id = pId;}
@OneToMany(targetEntity=B.class, mappedBy="a")
public List<B> getBs() {return bs;}
public void setBs(List<B> pBs){bs = pBs;}
}
and
@Entity
@table(name="b")
public class B {
private int id;
private A a;
@Id
public int getId() {return id;}
public void setId(int pId){id = pId;}
@ManyToOne(targetEntity=A.class)
@JoinColumn(name="a")
public A getA() {return a;}
public void setA(A pA){a = pA;}
}
when the tables are:
a
id
------
1
b
id | a
---|---
1 | 1
2 | 1
one might expect that the query created from
SELECT DISTINCT a
FROM A a
LEFT JOIN FETCH a.bs
will return a list containing one entity.
Instead, the query returns a list containing twice the same instance of the entity, since it creates one entity for every row (although it doesn't recreates entities, so it is the same instance twice).
It seems like a bug.
It is possible to fix it in Loader (while populating the list), what should be done?
Hibernate version:3.1.rc2
Name and version of the database you are using:oracle9i
The generated SQL (show_sql=true): select distinct a0_.id as id2_0_, bs1_.id as id8_1_, bs1_.a as a8_1_, bs1_.a as a0__, bs1_.id as id0__, from a a0_ left outer join b bs1_ on a0_.id = bs1_.a
|