我有两个实体:
@Entity
public class FuturePlan {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int fpId;
private String about;
private Date travelDate;
@ManyToOne(fetch=FetchType.LAZY)
private User user;
@ManyToOne(fetch=FetchType.LAZY)
private Location location;
....contructors and get/set
...和
@Entity
public class Location {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int lId;
private String lName;
....contructors and get/set
如何获取futurePlan
的所有location.name == "Something"
个实例?
答案 0 :(得分:1)
1.您可以很好地使用如下所示的原生查询:
String q="select * from employer employer,employee where employer.id=
employee.employerId and employee.location='xyz'";
Query query= em.createNativeQuery(q,Object[].class);
List<Object[]> students= query.getResultList();
您也可以使用HQL获得相同的结果。
您也可以使用条件查询。