Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Native query mapping requires JPA annotations
Native query mapping requires JPA annotations [message #534025] Mon, 17 May 2010 14:14 Go to next message
Eclipse UserFriend
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 Go to previous message
Eclipse UserFriend
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?
Previous Topic:Eclipselink 2.0 with Spring 3: has anyone yet managed it
Next Topic:Problem with EclipseLink JPA 1.0 and Glassfish 2.1
Goto Forum:
  


Current Time: Wed Jul 23 04:32:25 EDT 2025

Powered by FUDForum. Page generated in 0.27089 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top