Closed as not planned
Description
Hello Spring Team.
in the document: no nested projections can be applied
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections.dtos
I developed the code as application, did some tests and results. It is possible to query dynamically, without specifying the join type, lazy fields can join automatically without using join fetch or EntityGraph. Compared to the normal Entity class (even when querying the same fields), the speed of the select query is much faster.
@Data
public class UserDto1 {
private Long id;
private String email;
private String password;
private AdressDTO1 adressDTO;
public UserDto1(Long id, String email, String password, Long adressId, int adressNo, String adressHouse) {
this.id = id;
this.email = email;
this.password = password;
this.adressDTO = new AdressDTO1(adressId, adressNo, adressHouse);
}
}
@Data
@AllArgsConstructor
public class AdressDTO1 {
private Long id;
private int no;
private String house;
}
public interface UserRepository extends JpaRepository<User, Long> {
public <T> List<T> findBy(Class<T> clazz);
}
@Data
@Builder(setterPrefix = "set")
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table
public class User {
@Id
@SequenceGenerator(name = "user_sequence", sequenceName = "sq_user",allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_sequence")
private Long id;
@Column
private String email;
@Column
private String password;
@ManyToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
@ToString.Include(name = "id")
private Adress adress;
}