2017-10-18 7 views
0

J'essaie de mapper une vue avec l'objet resultset que j'obtiens après avoir interrogé Postgres DB dans Spring JPA. Mais je ne sais pas comment faire, toute aide sera appréciéeMapper une vue avec l'objet de résultat de base de données

@Query(nativeQuery = true, value = "select e.job_number, p.tag_number, e.drawing_number, p.part_number, " 
      + "eoa.operation_order, peoa.name, peoa.status, peoa.comment, peoa.last_updated_by, " 
      + "peoa.last_updated_date, peoa.revtype " 
      + "from brs.events e " 
      + "join brs.parts p on e.id = p.event_id " 
      + "join brs.event_operations_audit eoa on eoa.event_id = e.id " 
      + "join brs.part_event_operations_audit peoa on peoa.part_id = p.id and peoa.event_operation_id = eoa.id " 
      + "where e.id = :eventId " 
      + "and e.is_received = true " 
      + "and e.is_workscope_reviewed = true " 
      + "order by p.tag_number, eoa.operation_order, peoa.last_updated_date ") 
    Set<Object> getJobPartRecentActivityData(@Param("eventId")Long eventId); 

https://pastebin.com/iDZDhpce

Répondre

0

Ceci peut être réalisé par l'exemple suivant. Créer une classe BookValueMappig dire

@SqlResultSetMapping(
     name = "BookValueMapping", 
     classes = @ConstructorResult(
       targetClass = BookValue.class, 
       columns = { 
        @ColumnResult(name = "id", type = Long.class), 
        @ColumnResult(name = "title"), 
        @ColumnResult(name = "version", type = Long.class), 
        @ColumnResult(name = "authorName")})) 

Puis, dans l'APP incluent le fichier de mapping:

List<BookValue> results = this.em.createNativeQuery("SELECT b.id, b.title, b.version, a.firstName || a.lastName as authorName FROM Book b JOIN Author a ON b.author_id = a.id", "BookValueMapping").getResultList();