I am using play framework with jpa. I have a Jobads model with 2 functions for 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 typing as the output of a function in my console. findall () works fine, but findByLocation () is giving me an exception. [ClassCastException: [Ljava.lang.Object; cannot be applied to models. Jobads]
Why does this problem only occur in findByLocation () and what is the solution to this problem?
thank
source
to share