Reputation: 177
I'am trying to make a join between two entities using j2ee and hibernate. But I get the following error:
java.lang.IllegalArgumentException: Type specified for TypedQuery is incompatible with query return type [class java.lang.Double]
This is the query that I'm trying to get work
Query query = entityManager
.createQuery("SELECT avg(responseEnd - responseStart) FROM QualiteDeService q join q.test",QualiteDeService.class );
And these are the entities:
@Entity
public class QualiteDeService {
private int id_qualite_service;
private Test test;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId_qualite_service() {
return id_qualite_service;
}
@ManyToOne
@JoinColumn(name = "id_test", referencedColumnName = "id_test", insertable = false, updatable = false)
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
}
@Entity
public class Test implements Serializable{
private int id_test;
private int note;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId_test() {
return id_test;
}
public void setId_test(int id_test) {
this.id_test = id_test;
}
}
Upvotes: 2
Views: 21652
Reputation: 1457
The query return type need be compatible with the entity object in which you want to cast it. Update your code
entityManager.createQuery("SELECT avg(responseEnd - responseStart) FROM QualiteDeService q join q.test",Double.class );
Upvotes: 8