Using sleep mode

Let's say we have one relationship between the client and the phone.

class Customer{ @OneToMany(cascade = {CascadeType.ALL},mappedBy = "customer", fetch = FetchType.LAZY) @Fetch( FetchMode.SELECT) private List<Phone> phoneList; } 

In the above code, what is the difference between fetch = FetchType.LAZY and FetchMode.SELECT.

I read that they are both the same, that is, they lazily load the base collection.

Can someone explain to me which one to use when?

+6
source share
1 answer

The type of fetch (lazy / impatient) refers to when Hibernate will receive the connection, whether it will receive the object (impatient) or expect the code to request an association (lazy).

The select / join mode refers to how Hibernate will receive the association, i.e. whether it uses an optional SELECT statement or uses a join.

Some combinations of them make no sense, for example. lazy + join. If you are using lazy sampling, then the SELECT sampling mode that you can do is selected.

If you use reliable sampling, you can choose either sampling mode.

+13
source

Source: https://habr.com/ru/post/906546/


All Articles