-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: NamedNativeQuery: not found column obtained only one column
PostPosted: Wed Nov 07, 2012 1:39 pm 
Newbie

Joined: Wed Nov 07, 2012 1:28 pm
Posts: 5
Hello, guys.

I have a very strange problem ( for me, I'm a newbie in hibernate-jpa). I have readed papers and documentation but I can't found a solution.

I'm going to explain my problem:

I have created this query:

Code:
@NamedNativeQueries({

@NamedNativeQuery(name = "DatosAcademicos.findDatosAcademicosByIdSolicitante", query = "SELECT da.DATO_ACADEMICO_ID,da.CURSO_ACADEMICO"
      + " FROM Datos_Academicos da WHERE da.SOLICITANTE_ID=:solicitanteId", resultClass = DatosAcademicos.class)

})


My Entity has 3 parameters:

Code:
public class DatosAcademicos extends GeneralDomainObject implements
      Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 4463742762840808393L;

   @Id
   @Column(name = "DATO_ACADEMICO_ID")
   private Long datoAcademicoId;

   @Column(name = "CURSO_ACADEMICO")
   private Integer cursoAcademico;

   @Column(name = "CONFIRMADA")
   private Integer confirmada;
}


Hibernate always say to me:
could not read column value from result set: CONFIRMADA; Nombre de columna no vĂ¡lido.

This is my execution:

Code:
public List<DatosAcademicos> findDatosAcademicosByIdSolicitante(
         Long idSolicitante) throws GeneralDAOException {
      try {
         return (List<DatosAcademicos>) getJpaTemplate()
               .getEntityManager()
               .createNamedQuery(
                     "DatosAcademicos.findDatosAcademicosByIdSolicitante")
               .setParameter(
                     "solicitanteId",
                     (idSolicitante != null ? idSolicitante
                           : Long.MIN_VALUE)).getResultList();
      } catch (Exception e) {
         logger.error("Error en DatosAcademicosDAOImpl " + e.getMessage());
         throw new GeneralDAOException(e.getMessage(), e.getMessage(), e);
      }
   }



If I do query in this way:
Code:
@NamedNativeQueries({

@NamedNativeQuery(name = "DatosAcademicos.findDatosAcademicosByIdSolicitante", query = "SELECT da.*
      + " FROM Datos_Academicos da WHERE da.SOLICITANTE_ID=:solicitanteId", resultClass = DatosAcademicos.class)


all works fine; so... What's the problem here?.

Does hibernate allow get only 1 column in native query binding it to an object?.

Thanks in advance.

English is not my native language, sorry for my poor way of writing. :(


Top
 Profile  
 
 Post subject: Re: NamedNativeQuery: not found column obtained only one column
PostPosted: Thu Nov 08, 2012 6:08 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
When you map a query-result to a entity class
Quote:
resultClass = DatosAcademicos.class

then the result always must contain all persistent properties of that specific entity class.
In case of SELECT da.* it contains all required columns, so it works.
In case of SELECT da.DATO_ACADEMICO_ID,da.CURSO_ACADEMICO the column CONFIRMADA is missing
in the result set, so hibernate can't fill these value properly in the DatosAcademicos object.
Therefore you get the excpetion you reported above.


Top
 Profile  
 
 Post subject: Re: NamedNativeQuery: not found column obtained only one column
PostPosted: Thu Nov 08, 2012 12:21 pm 
Newbie

Joined: Wed Nov 07, 2012 1:28 pm
Posts: 5
Many thanks!.

I'm going to write my own Query class to override this behaviour. :D

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.