I'm using hibernate 3.6.10 and I'm facing this situation.
I have:
table A: a_id, a_name, a_desc
table B: b_id, b_name, a_id
and one A can be in many Bs
I want to do a one way ManyToOne join
So I've got:
@Entity
@Table(name = "B")
public class B {
@ManyToOne(fetch = FetchType.EAGER)
@Cascade(CascadeType.ALL)
@JoinColumn(name = "a_id")
private A a;
@Column(name = "b_name")
private String b_name;
...
}
@Entity
@Table(name = "A")
public class A {
@Id
@Column(name = "a_id")
private Integer id;
....
}
Then I do:
sessionFactory.getCurrentSession().createCriteria(B.class).list();
PROBLEM is: It does the outter left join but it only brings 1 of entity A for all of Bs.
It should bring:
row 1: B: 1 | 1stName | 32 (a_id & a_name & a_desc)
row 1: B: 2 | 2ndName | 69
row 1: B: 3 | 3rdName | 45
row 1: B: 4 | 4thName | 94
row 1: B: 5 | 5thName | 32
but it brings:
row 1: B: 1 | 1stName | 32 (a_id & a_name & a_desc)
row 1: B: 2 | 2ndName | 32
row 1: B: 3 | 3rdName | 32
row 1: B: 4 | 4thName | 32
row 1: B: 5 | 5thName | 32
It looks like Hibernate does the correct query with the correct join, which if I run it manually in the DB brings as expected. It sounds to me I'm having a problem on how hibernate/annotations are configured.
I can see in the logs the correct values for Entity B, but for some reason it only uses one (id 32) for all the Bs.
Any ideas?
I hope this question makes seance.
thanks!