Hello,
I am trying to test some JPQL queries from Hibernate Console (I hope to see same results when executing the same query onces the application had been deployed).
I am using "Hibernate Tools for Eclipse Version: 3.4.0.v20110215-1252-H31-GA". The underlying database is Postgres 9. I am using Java 6 version. Entity specification is using JPA annotations.
I have execute severals JPQL queries without a problem, but when I try the SELECT NEW options I am having a lots of problems.
I am trying to execute this JPQL query:
Code:
select new com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto(emp.id)
from Empleado emp
inner join emp.posicion pos
order by emp.numberOfEmployer asc
This the code for EmployeeValuationItemDto:
Code:
public class EmployeeValuationItemDto extends Identifiable implements Serializable {
private static final long serialVersionUID = -4952492515912224254L;
private String employeeNumber;
private String name;
private String surname1;
private String surname2;
private String positionName;
private Long positionValuation;
public EmployeeValuationItemDto() {
super();
}
public EmployeeValuationItemDto(Long id) {
super(id);
}
public EmployeeValuationItemDto(String name) {
super();
this.name = name;
}
public EmployeeValuationItemDto(String name, String surname1) {
super();
this.name = name;
this.surname1 = surname1;
}
public EmployeeValuationItemDto(Long id, String employeeNumber,
String name, String surname1, String surname2, String positionName,
Long positionValuation) {
super(id);
this.employeeNumber = employeeNumber;
this.name = name;
this.surname1 = surname1;
this.surname2 = surname2;
this.positionName = positionName;
this.positionValuation = positionValuation;
}
...
The parent class Identificable has this code:
Code:
public abstract class Identifiable implements Serializable {
private static final long serialVersionUID = -2392844426723727004L;
private Long id;
public Identifiable() {
super();
}
public Identifiable(Long id) {
super();
this.id = id;
}
The view "Hibernate Dynamic SQL Preview" is showing this message:
Quote:
org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto] [select new com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto(emp.id)
from com.ef.cahs.model.empleados.Empleado emp
inner join emp.posicion pos
order by emp.numberOfEmployer asc]
I don't know what's going on here. I have tried several configurations... some works others dont. For instance:
Case 1. Exception -> Unable to locate appropriate constructor (emp.id is a Long property)
Code:
select new com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto(emp.id)
...
Case 2. Works fine (emp.nombre is an String property)
Code:
select new com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto(emp.nombre)
...
Case 3. Exception -> Unable to locate appropriate constructor (emp.id and emp.apellido1 are both String properties)
Code:
select new com.ef.cahs.commons.dto.organization.EmployeeValuationItemDto(emp.nombre, emp.apellido1)
...
As you can see on EmployeeValuationItemDto class there are several Constructors, one for each case so I don't understand why is UNABLE to find the constructor. Case 1 is using a constructor with type Long. Case 2 is using a constructor with type String. Case 3 is using a constructor with types (String , String)...
I have looked the documentation, books and over the internet and I dont know what's going on here. Am I doing something wrong? I think that this is a simple case... so...
Well, thanks a lot in advance and I hope that some one can help me cause I am stuck her
BR
Nacho