Я определил свои классы моделей, как показано ниже.
@Entity
@Table(name = "my_employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "emp_address_mapping", joinColumns = @JoinColumn(name = "emp_id"), inverseJoinColumns = @JoinColumn(name = "address_id"))
private List<Address> addresses = new ArrayList<Address>();
.......
.......
}
@Entity
@Table(name = "my_address")
public class Address {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String country;
.....
.....
}
public class EmployeeDetails {
private int empId;
private String name;
private String country;
......
......
}
Как написать запрос, используя аннотацию @Query для заполнения всех EmployeeDetails.
public interface EmployeeRepository extends CrudRepository<Employee, Integer> {
@Query("SELECT new com.sample.app.model.EmployeeDetails......")
List<EmployeeDetails> getEmployeeDetails();
}