Native query mapping requires JPA annotations [message #534025] |
Mon, 17 May 2010 14:14  |
Eclipse User |
|
|
|
It's possible using openjpa to get the result of native query in a regular class (without jpa annotations). The following query works with eclipselink if and only if NomeAluAux has JPA column, id and entity annotations. With openjpa the annotations are not necessary and they are replaced for columns alias written in the query itself:
Query query = em.createNativeQuery("Select NRO_INT_ALU nroIntAlu, NOME_ALU nomeAlu from APM_ALUNO ", NomeAluAux.class);
Beside being a inconvenience for those who are migrating from one implementation to the other,
it's a big inconvenience when the native query returns an aggregation value that is not mapped on the table. In this case, the object properties must be populated manually.
It would be a improvement in eclipselink if there was an option to work like that.
///@Entity
public class NomeAluAux {
// @Id
// @Column(name="NRO_INT_ALU")
Integer nroIntAlu;
// @Column(name="NOME_ALU")
String nomeAlu;
public NomeAluAux(Integer nroIntAlu, String nomeAlu) {
this.nroIntAlu = nroIntAlu;
this.nomeAlu = nomeAlu;
}
public NomeAluAux() {
}
public NomeAluAux(String nomealu) {
}
public Integer getNroIntAlu() {
return nroIntAlu;
}
public void setNroIntAlu(Integer nroIntAlu) {
this.nroIntAlu = nroIntAlu;
}
public String getNomeAlu() {
return nomeAlu;
}
public void setNomeAlu(String nomeAlu) {
this.nomeAlu = nomeAlu;
}
}
|
|
|
Re: Native query mapping requires JPA annotations [message #534866 is a reply to message #534025] |
Thu, 20 May 2010 10:18  |
Eclipse User |
|
|
|
You could use a constructor query in JPQL. Or wrap the result yourself using the class, or use a redirector query.
Or log an enhancement request.
Since you are already defining a class for the SQL, is it really much more work to define annotations, if you are naming the fields the same the only thing you really need to do is define @Entity?
|
|
|
Powered by
FUDForum. Page generated in 0.27089 seconds