I am using play framework with jpa. I have a model Jobads with 2 functions to findall() findByLocation()
My Model
public class Jobads {
@Id
@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
@ManyToOne
private Jobindistry industry;
@ManyToMany
@JoinTable(
name = "jobads_city",
joinColumns = {@JoinColumn(name = "jobads_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "city_id", referencedColumnName = "id")})
private List<City> city;
}
findall()
public static List<Jobads> findall() {
@SuppressWarnings("unchecked")
List<Jobads> el = JPA.em().createQuery("from Jobads order by id").getResultList();
return el;
}
findByLocation()
public static List<Jobads> findByLocation(String location) {
List<Jobads> jadList = JPA.em().createQuery("FROM Jobads j join j.city c WHERE c.name LIKE :location ").setParameter("location", "%" + location + "%").getResultList();
return jadList;
}
I am printing both the function output in my console findall() works fine but findByLocation() gives me an exception [ClassCastException: [Ljava.lang.Object; cannot be cast to models.Jobads]
Why this problem in occuring only in findByLocation() and what is the solution of this problem??
Thanks