0

I have table employee

@Entity
@Table(name = "employee")
public class Employee {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="emp_id")
    private Long id;
    
    @Column(name="emp_name")
    private String empName;
    
    @Column(name="emp_mail")
    private String empMail;
    
    @Column(name="emp_no")
    private String empNo;

    @Column(name="emp_salary")
    private Long empSalary;
    
    @Column(name="type_id")
    private Long typeId;

}

In addition, I have table employeetype whose primary key type id is in employee table enter image description here

How i am able to get response containg type_name not type_id in java data jpa for api using jparepository. how to join table data.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Subash
  • 1
  • 1
  • If you want to get a record which does not exactly match an entity, you can build DTO class with the attributes you need and create a query with the syntax: `select new DTO(e.a, e.b ...) from Entity e join ...` see https://stackoverflow.com/questions/23719237/mapping-jpa-or-hibernate-projection-query-to-dto-data-transfer-object – Pierre Demeestere Nov 13 '22 at 07:07
  • BTW, as you have an `employeetype` table, you can make a jpa entity `EmployeeType` out of it, and change the `typeId` on Employee to a `@ManyToOne` relation to `EmployeeType`. This design will help you building the query to get the type name of an employee. – Pierre Demeestere Nov 13 '22 at 07:11

0 Answers0