Reputation: 270
I have two entities:
@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
...and
@Entity
public class Location {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int lId;
private String lName;
....contructors and get/set
How to get all futurePlan
instances where location.name == "Something"
?
Upvotes: 0
Views: 297
Reputation: 1967
1.You can very well use native Query something like below:
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();
You can also achieve the same results by using HQL as well.
You can use Criteria Query too.
Upvotes: 1