Description:
I have two tables, Shop_Employee and Shop_Employee_Type. I wanna display typeName directly when show the employee detail information, but I don't want to config the relationship(OneToMany or ManyToOne) between this two entity.
Because this will load all Shop_Employee_Type column's value, but these values are useless for me, I just need typeName of Shop_Employee_Type.
Below is my code, but it doesn't work.
ShopEmployeeType:
@Entity
@Data
//@DynamicUpdate
public class ShopEmployeeType {
@Id
private String typeId;
private String shopId;
private String typeName;
private Integer typeStatus;
private String typeDescription;
}
Shop_Employee:
@Entity
@Data
public class ShopEmployee {
@Id
private String employeeId;
private String shopId;
private String typeId;
private String name;
private String code;
private String phone;
private Integer status;
private String idcardNumber;
private String image;
//@Transient
private String typeName;
public ShopEmployee() {
}
}
Repository:
@Query(value = "select u.*,t.type_name from shop_employee u inner join shop_employee_type t on u.type_id=t.type_id", nativeQuery = true)
List<ShopEmployee> findAllData();
This could show typeName as I wished, but there is an error appears when I save a new entity Shop_Employee; If I add a @Transient for 'typeName', It could save successfully, but the value of 'typeName' is null when I query entity Shop_Employee.