How to map a NamedNativeQuery in a class that doesn't correspond to a single table
<p>I've got a legacy SQL Server database, and they've given to me a query, which does some join between several tables. </p>

<blockquote>
  <p>SELECT TipoDia, ServBus, Instante, Evento, [VistaHorariosActivos].Linea, Coche, [VistaHorariosActivos].Sublinea, [VistaHorariosActivos].Seccion, Punto, Tipo, Viaje, Operador, Fecha, [VistaHorariosActivos].Macro, Ruta, OrdenSeccion FROM [SAEBase].[dbo].[VistaHorariosActivos] INNER JOIN [SAEBase].[dbo].[LineaSublineaSeccionOrden] ON [VistaHorariosActivos].Macro = LineaSublineaSeccionOrden.Macro AND [VistaHorariosActivos].Linea = LineaSublineaSeccionOrden.Linea AND [VistaHorariosActivos].Sublinea = LineaSublineaSeccionOrden.Sublinea AND [VistaHorariosActivos].Seccion = LineaSublineaSeccionOrden.Seccion WHERE Fecha>:fecha AND VistaHorariosActivos.Macro=:macro AND VistaHorariosActivos.Linea=:linea AND (Evento = 1 OR Evento = 5)</p>
</blockquote>

<p>I want to map these results into a java class (TripDTO): I've got every column mapped with their proper data type.</p>

<p>The issue is that I don't know whether the TripDTO class should have the @Entity and @table annotations. Actually, that query isn't related to a single table. </p>

<p>Can somebody help me out defining that class?</p>

<p>Here you are the code:</p>

<pre><code>package model;

import java.io.Serializable;
import java.time.LocalDateTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

@NamedNativeQueries({
    @NamedNativeQuery(
        name = "getTripDtos",
        query = "&lt;&lt;the query&gt;&gt;",
        resultClass = TripDTO.class
    )   
})
@Entity
@Table(name = "???")
public class TripDTO implements Serializable {

    /*
     * Atributos 
     */
    private static final long serialVersionUID = 5719572417390931185L;

    @Id
    @Column(name = "Macro", insertable = false, updatable = false)
    @Type(type = "usertype.IdMacroUserType")
    private Short macro;
    @Id
    @Column(name = "Linea", insertable = false, updatable = false)
    private Short linea;
    @Id
    @Column(name = "Sublinea", insertable = false, updatable = false)
    private Byte sublinea;
    @Id
    @Column(name = "Seccion", insertable = false, updatable = false)
    @Type(type = "usertype.IdSeccionUserType")
    private Integer seccion;
    @Id
    @Column(name = "Punto", insertable = false, updatable = false)
    private Integer punto;
    @Id
    @Column(name = "Instante", insertable = false, updatable = false)
    private Integer instante;

    @Column(name = "TipoDia", insertable = false, updatable = false)
    @Type(type = "usertype.TipoDiaUserType")
    private String tipoDia;
    @Type(type = "usertype.ServicioBusUserType")
    @Column(name = "ServBus", insertable = false, updatable = false)
    private Integer servBus;
    @Column(name = "Evento", insertable = false, updatable = false)
    @Type(type = "usertype.TipoEventoUserType")
    private Short evento;
    @Column(name = "Coche", insertable = false, updatable = false)
    private Byte coche;
    @Column(name = "Tipo", insertable = false, updatable = false)
    @Type(type = "usertype.TipoNodoUserType")
    private Short tipo;
    @Column(name = "Viaje", insertable = false, updatable = false)
    private Integer viaje;
    @Column(name = "Operador", insertable = false, updatable = false)
    private String operador;
    @Column(name = "Fecha", insertable = false, updatable = false)
    private LocalDateTime fecha;
    @Column(name = "Ruta", insertable = false, updatable = false)
    private Integer ruta;
    @Column(name = "OrdenSeccion", insertable = false, updatable = false)
    private Integer ordenSeccion;
    ...
</code></pre>