I needed a RoleMappingService class(which is annotated by @Service) object into a Employee class (which is annotated by @Entity)
below are my classes
********************* RoleMappingsService class **********************
@Service
public class RoleMappingsService {
@Autowired
RolesMappingDao rolesMappingDao;
public List<RolesMappings> getRolesMappingByauthSystemRole(String authSystemRole) {
return rolesMappingDao.getRolesMappingByauthSystemRole(authSystemRole);
}
}
############### Employee class
@Configurable
@Component
@Entity
@NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")
public class Employee implements Serializable, UserDetails {
@Autowired
@Transient
RoleMappingsService roleMappingsService;
public static final String STATUS_ACTIVE = "ACTIVE";
public static final String STATUS_INACTIVE = "INACTIVE";
public static final String STATUS_LOCKED = "LOCKED";
public static final String STATUS_ONLEAVE = "ONLEAVE";
public static final String STATUS_EXPIRED = "EXPIRED";
private static final long serialVersionUID = 1L;
@Id
@Column(name = "emp_id")
private String empId;
@Column(name = "emp_password")
private String empPassword;
@Column(name = "emp_email")
private String empEmail;
@Column(name = "emp_address")
private String empAddress;
@Column(name = "emp_age")
private int empAge;
@Column(name = "emp_firstname")
private String empFirstname;
}
Here Autowire is not working for roleMappingsService and the object is always found null. However I tried to autowire same object in some other service and there Autowire is perfectly working.
( I know Entity class is only used for representing database table but in my case I need to set some field values which depend on another table so need to fetch data using service)