Search code examples
javaoracle-databasejpaselectionclause

Selection Of data using "as" clause Using JPA


As I know, using SQL we can select the data with customised form like the query below:

select '<Root value=\"'"|| databaseColumnValue || '\"'" as displayItem from Table";

The selected value looks like below:

<Root value = 10 />

I have tried many ways in JPA to achieve this and haven't found one.

How can I achieve this kind of functionality using JPA ?


Solution

  • Try with CONCAT function (of course, adjust it to your entities)

    select CONCAT('< Root value = ', myEntityField, ' />') as displayItem from MyEntity
    

    I don't know what combinations did you try, but this works also, at least it does with Hibernate (thanks to @Lalit Kumar B for pointing this out)

     select '< Root value = ' || myEntityField || ' />' as displayItem from MyEntity