我有一个旧的 SQL Server 数据库,他们给了我一个查询,它在几个表之间进行了一些连接。
选择 TipoDia、ServBus、Instante、Evento、[VistaHorariosActivos].Linea、Coche、[VistaHorariosActivos].Sublinea、[VistaHorariosActivos].Seccion、Punto、Tipo、Viaje、Operador、Fecha、[VistaHorariosActivos].Macro、Ruta、OrdenSecion FROM [ SAEBase].[dbo].[VistaHorariosActivos] INNER JOIN [SAEBase].[dbo].[LineaSublineaSeccionOrden] ON [VistaHorariosActivos].Macro = LineaSublineaSecionOrden.Macro AND [VistaHorariosActivos].Linea = LineaSublineaSecionOrden.Linea AND [VistaHorariosActivos].Sublinea = LineaSublineaSecionOrden.Sublinea AND [VistaHorariosActivos].Secion = LineaSublineaSecionOrden.Secion WHERE Fecha>:fecha AND VistaHorariosActivos.Macro=:macro AND VistaHorariosActivos.Linea=:linea AND (Evento = 1 OR Evento = 5)
我想将这些结果映射到一个 java 类 (TripDTO) 中:我已经将每一列都映射到了它们正确的数据类型。
问题是我不知道 TripDTO 类是否应该有 @Entity 和 @table 注释。实际上,该查询与单个表无关。
有人可以帮我定义那个类吗?
这是代码:
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 = "<<the query>>",
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;
...