次のような 2 つのオブジェクト間に OneToMany/ManyToOne 関係があります。
public class Company {
private Long compid;
private String companyName;
@OneToMany(mappedBy = "company", cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
private List<Employee> employees;
}
public class Employee {
private Long empid;
private String fstName;
private String lstName;
private String sal;
@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@NotFound(action = NotFoundAction.IGNORE)
@JoinColumn(name = "compid", nullable = true)
private Company company;
}
を持っている社員を獲得したいcompany.companyName like xxxx%
。私は次のようなものを試しました:
Criteria criteria = session.createCriteria(Employee.class);
criteria.createAlias("company", "company");
criteria.add(Restrictions.like("company.companyName ", "xxxx%"));
return criteria.list();
しかし、私はエラーが発生します:
could not resolve property: company.companyName of: Employee
このコードのどこに問題がありますか?