Mình Mapping giữa 2 bảng có mối quan hệ onetomany mà bị gặp lỗi do câu sql nhưng chạy trong mySql thì không bị gì ?
Mình generate Entities -> Tables : “spring.jpa.hibernate.ddl-auto=create”
Company :
@Entity
@Table(name = "company")
public class Company {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column
private String name;
@Column
private String location;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "company")
private List<Employee> employee;
Employee :
@Entity
@Table(name = "employee")
public class Employee {
@Id
@GeneratedValue
private int id;
@Column
private String name;
@Column
private int age;
@ManyToOne
@JoinColumn(name = "company_id" ,nullable = false)
private Company company;
Repository :
public interface EmployeeRepository extends JpaRepository<Employee, Integer>{
/*@Query("select e from employee e inner join e.company")*/
@Query("select e.name from company c , employee e where c.id=e.company_id and c.id = ?1")
List<Employee> getAllEmployeeInCompany(int id);
}
Lỗi :
MySql chạy hoàn toàn bình thường !
Mình Cảm ơn !