Hello
I want to avoid hibernate to do a select when there is no data on foreign table.
I explain :
I have 2 tables A and B with this kind of association
A(1...1) ----(0...1)BIf I load (with criteria) all datas on the table A, I have the correct behavior
Code:
Select * from A left outer join B on a.code=b.id
with a.code not primarykey of A table
But after I have some others selects:
Code:
Select * from B where id=?
Each time I have no B object according to the A object
In my actual case, I have 662 records, but only 4 records contain a mapping with B object ... So I have 658 selects to check if the B object exists in DB
It's inefficient ! But I don' know how fix it
this is my java code for the association :
Code:
@OneToOne( fetch = FetchType.EAGER, cascade = {
CascadeType.ALL
})
@Fetch(FetchMode.JOIN)
@JoinColumn(name = "code", insertable = false, updatable = false)
@NotFound(action = NotFoundAction.IGNORE)
public B getB() {
return b;
}
Note: I try with optional=true, but it's the same ...
Thanks in advance for your help