Spring custom @Query with incrementable variable

Antoine :

I have a query that map to a Custom Object :

@Query("SELECT new com.mypackage.CmcXml(c.nom, c.prenom, c.genre "+
                "FROM Cmc c")
List<CmcXml> getExportCmc();

So I get this kind of result :

{"NOM1", "PRENOM1", "GENRE1"},
{"NOM2", "PRENOM2", "GENRE2"},
{"NOM3", "PRENOM3", "GENRE3"}

I would like to have an counter that increment while retrieving the data :

@Query("SELECT new com.mypackage.CmcXml(myCounter, c.nom, c.prenom, c.genre "+
                "FROM Cmc c")
List<CmcXml> getExportCmc();

The result I want :

{1, "NOM1", "PRENOM1", "GENRE1"},
{2, "NOM2", "PRENOM2", "GENRE2"},
{3, "NOM3", "PRENOM3", "GENRE3"}

Is it possible to do it in the @Query or do I have to go through all the list after the request ?

Srinivasan Sekar :

No , row number is not supported in jpa/hibernate. you have to use native query.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=157089&siteId=1