I have a entity as follows
@Entity
public class User {
@Id
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
private Type type;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
}
Call findOne () or findAlll () on this entity generated different sql
findAll()
Hibernate:
select
user0_.id as id1_1_,
user0_.type_id as type_id2_1_
from
user user0_
Hibernate:
select
type0_.id as id1_0_0_,
type0_.name as name2_0_0_
from
type type0_
where
type0_.id=?
findOne()
Hibernate:
select
user0_.id as id1_1_0_,
user0_.type_id as type_id2_1_0_,
type1_.id as id1_0_1_,
type1_.name as name2_0_1_
from
user user0_
left outer join
type type1_
on user0_.type_id=type1_.id
where
user0_.id=?
why findAll() generated sql do not use join?
I create a example repositorie by this question
https://github.com/wensimin/jpa-join-query
thanks!