1

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>>?

4 Answers4

0

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>.

rg226965
  • 61
  • 2
0

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();
0

You can provide a PROJECTION entity which will have 3 attributes and must provide a parametrized constructor with those 3 attributes you want to fetch ,or you can still get them as a List<Object[]> and then hydrate your entity.

karim farhouti
  • 310
  • 1
  • 7
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 19 '22 at 11:53
0

I've tried those things but what worked for me is using ctid as an @Id. Since I only needed some sort of a mock id, it worked fine.

Jhanzaib Humayun
  • 1,193
  • 1
  • 4
  • 10