This discussion is archived
5 Replies Latest reply: Jan 24, 2013 3:58 AM by 911689 RSS

SQLResultSetMapping Not Working... Array brings only the entity

911689 Newbie
Currently Being Moderated
Hi !. My problem is the following one... Considering this code... The different arrays brought by List collections has only size equal to "1" and not "3" as I was expecting... Does anyone know which part of the code would I need to modify ?.

The code in my EJB is:

String query = "";
query +=
"SELECT VDNA.*," +
"(SELECT PAR_DESCRIPCION FROM PARAMETROS WHERE PAR_CODIGO = 'TIPO_DOCUMENTO' AND PAR_VALOR = VN_DOC_TIPO) AS tipoDeDocumento," +
"decode(VN_SEXO,1,'Masculino',2,'Femenino') as tipoSexo FROM VEND_NEVADA VDNA";

List rights = em.createNativeQuery(
query,"qVendedoresNevada")
.getResultList();
// so get results back as Object []
// and now you can output results
for(Object object : rights){

int cantidad = 0;
}

My entity annotations are:

@Entity
@Table(name = "VEND_NEVADA")
@SqlResultSetMapping(name="qVendedoresNevada",
entities={
@EntityResult(entityClass=com.tnevada.apercuen.model.entities.VendNevada.class)},
columns={
@ColumnResult(name="tipoDeDocumento"),
@ColumnResult(name="tipoSexo")}
)
public class VendNevada implements Serializable {

What I wanted to say is that, the "object" variable is an Array of size "1"...

Thankx !. I will be checking out...

Cheers
  • 1. Re: SQLResultSetMapping Not Working... Array brings only the entity
    JamesSutherland Pro
    Currently Being Moderated
    The result Object[] should be of size 3. What do you get back exactly?

    Ensure you have recompiled/deployed your code, and don't have two result set mappings with the same name.

    Try it with just the @ColumnResult's, does this give you 2 elements?
  • 2. Re: SQLResultSetMapping Not Working... Array brings only the entity
    911689 Newbie
    Currently Being Moderated
    Indeed, the array is of size equal to "3". In the first slot, I can find my entityty object but hte other 2 are null.
    I have tried only with ColumnResult and nothing happens... I will post again the code that gets more near what I want...

    Cheers !. Thankx !.
  • 3. Re: SQLResultSetMapping Not Working... Array brings only the entity
    911689 Newbie
    Currently Being Moderated
    The case I told you, is with the entity "VendNevada" and the following SQL Result Set Mapping Annotations:

    @SqlResultSetMapping(name="qVendedoresNevada",
    entities={
    @EntityResult(entityClass=com.tnevada.apercuen.model.entities.VendNevada.class, fields={
    @FieldResult(name="vnId", column="VN_ID"),
    @FieldResult(name="vnDocTipo", column="VN_DOC_TIPO"),
    @FieldResult(name="vnDocNro", column="VN_DOC_TIPO"),
    @FieldResult(name="vnFechaNac", column="VN_FECHA_NAC"),
    @FieldResult(name="vnNombre", column="VN_NOMBRE"),
    @FieldResult(name="vnObservacion", column="VN_OBSERVACION"),
    @FieldResult(name="vnSexo", column="VN_SEXO")
    })},

    columns={
    @ColumnResult(name="tipoDeDocumento")}
    )

    I really don't know what's hapenning... :(
  • 4. Re: SQLResultSetMapping Not Working... Array brings only the entity
    cdelahun Pro
    Currently Being Moderated
    What version of EclipseLink are you using and does "tipoDeDocumento" in uppercase work : @ColumnResult(name="TIPODEDOCUMENTO")?
  • 5. Re: SQLResultSetMapping Not Working... Array brings only the entity
    911689 Newbie
    Currently Being Moderated
    Thankx for answering me cdelahun ! :D Let me tell you that the problem was really silly... If you consider this code...

    @SqlResultSetMapping (name = "qVendedoresNevadaFinal",
    entities = { @EntityResult(entityClass = VendNevada.class)},
    columns = {   @ColumnResult(name = "TIPO_DE_DOCUMENTO"),@ColumnResult(name = "TIPO_SEXO")
    })

    and the query...

    "SELECT VDNA.*," +
    "(SELECT PAR_DESCRIPCION FROM PARAMETROS WHERE PAR_CODIGO = 'TIPO_DOCUMENTO' AND PAR_VALOR = VN_DOC_TIPO) TIPO_DE_DOCUMENTO," +
    "decode(VN_SEXO,1,'Masculino',2,'Femenino') TIPO_SEXO FROM VEND_NEVADA VDNA";

    The only thing I modified was the aliases and the columnResult names, which I put them in uppercase... I tested this and I verified it was due to this... I've been developing with B.C. and it was a long time since I last used EJB so imagine... But anyway... Thankx you so much ! :D

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points