Home > Blockchain >  Is there a way to return collection instead of entity in @Repository's @Query
Is there a way to return collection instead of entity in @Repository's @Query

Time:04-19

I have a query:

@Query(
    value = "select name, age, now() from received.scheme ;", 
    nativeQuery = true

)
public {???} selectData()

I cannot create or return an entity for such a scheme as there is no natural id in it, so is there a way to return something like List<Triple<String, Int, LocalDateTime>>?

CodePudding user response:

you can create another class with the required properties which you want to retrieve from the database and then you can return that class as List<Class>.

CodePudding user response:

In your code you get the data from: scheme So the Entity SchemeEntity should contains those three fields:

  1. name
  2. age
  3. now (creationDate for example it depend on your logic)

Then your method should be like this:

@Query(value = "select name, age, now() from received.scheme ;", 
    nativeQuery = true
)
public List<SchemeEntity> selectData();
  • Related