1

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!

shali
  • 11
  • 3
  • https://stackoverflow.com/questions/36489133/why-spring-data-jpa-not-issuing-join-query – Maciej Kowalski Dec 14 '17 at 13:02
  • Hello, this question is used ManyToOne not OneToMany. under these circumstances there would not be more rows in the result set. why findOne() use join but findAll() not use join? – shali Dec 15 '17 at 02:27

0 Answers0