JPA - select with join - how to make two related tables -
i have 2 tables relacionship id_employee.
--------------------------- --------------------------- table employee table timesheet --------------------------- --------------------------- id_employee id_time name_employee date_entry --------------------------- quant_hour id_employee ---------------------------
i need select returns records table employe , hours in existing related table timesheet. employees not have hours recorded in timesheet table should appear in list because registered in employee table.
what jpql query ?
class employee
@entity public class employee { @id @generatedvalue private long id_employee; private string name_employee ; //gets , sets }
class timesheet
@entity public class timesheet { @id @generatedvalue private long id_time; private double quant_hour; private date date_entry; @manytoone private employee employee; //gets , sets }
provided both tables mapped correctly,the employee entity have attribute (or collection) of type timesheet entity, therefore, need list of employees:
select e employee e
jpa automatically retrieves timesheet (or list of timesheets) when want read employee entity.
Comments
Post a Comment