Here is my entity class :
@Entity
public class MyData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
public MyData() {
// ...
}
public MyData(String fieldList, Object ... values) {
// ...
}
// Getters and setters here...
}
Later , I want to execute this query :
SELECT NEW com.company.MyData('f1,f2,f3',t.f1,t.f2,t.f3) FROM my_data_table t WHERE 1=1
And this exception is raised:
Unable to locate appropriate constructor on class [package.MyData]
My query can contain 1,2 ,3 ... or more fields.
How can I help my JPA provider (hibernate) finding the constructor ?
Hibernate 3.6.8
JPA 2
Java 6
Here is how I solved my problem:
SELECT NEW com.company.MyData('f1,f2,f3',t) FROM my_data_table t WHERE 1=1
And my class looks like this now:
@Entity
public class MyData {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
public MyData() {
// ...
}
public MyData(String fieldList, MyData md) {
// ...
}
// Getters and setters here...
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments