1

I have entity AccountStatus and want to use next native query (I use Spring Data):

  @Query(value = "SELECT id, code, dscp, 'some address' as address, (SELECT bank_code FROM tbl_bank WHERE id = hdr.BANK_ID) AS CorresBank  from account_status", nativeQuery = true)
  List<AccountStatus> getAccountStatus();

DB table account_status has only next columns: id, code, dscp. I want to map 'some address' constant and CorresBank value from native query above to address field corresBank field of entity respectively.

How can I do that ? Is it possible ?

@Entity
@Table(name = "account_status")
public class AccountStatus {
  @Id
  String id;
  @Column
  String code;
  @Column
  String dscp;

  String address;
  String corresBank;  
}
Max
  • 21
  • 3
  • Is native query essential? why don't you use JPQL instead if possible!! see [this](https://stackoverflow.com/a/50272744/1056042) for further reference. – Arshad Ali Dec 31 '20 at 06:10
  • @ArshadAli, in native query I use sub-query and if I understood correct, if I will use JPQL AccountStatus class should has field for tbl_bank, isnt it ? And in that case I should make some additional efforts. – Max Dec 31 '20 at 09:45

0 Answers0