操作数类型冲突:datetime2与tinyint不兼容

问题描述 投票:1回答:2

我无法用现有信息解决我的问题

Operand type clash: datetime2 is incompatible with tinyint

只有在使用mssql时才会出现此问题,希望有人已经知道此问题的解决方案

切换到mssql时出现了很多问题,它仍然只是其中之一,因为我设法解决了一些问题

@Entity
@Table
public class DoseAssignment {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Integer id;

@NotNull
@Size(min = 2, max = 30)
@Column(length = 30, nullable = false)
private String number;

@NotNull
@Column(columnDefinition = "tinyint", nullable = false)
private Integer unit;

@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", 
timezone = "UTC")
private Date date;

@NotNull
@Column(nullable = false)
@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", 
timezone = "UTC")
private Date dateOpenPlan;

@NotNull
@Column(nullable = false)
@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", 
timezone = "UTC")
private Date dateClosePlan;

@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", 
timezone = "UTC")
private Date dateOpen;

@Temporal(TemporalType.DATE)
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", 
timezone = "UTC")
private Date dateClose;

@ManyToOne(fetch = FetchType.LAZY)
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private Personal givePersonal;

@ManyToOne(fetch = FetchType.LAZY)
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private WorkMode workMode;

@ManyToOne(fetch = FetchType.LAZY)
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
private ProgramDangerous program;

@NotNull
@Size(min = 2, max = 100)
@Column(length = 100, nullable = false)
private String content;

调节器

Page<Integer> page = repository.findId(department == null ? null : new Department(department), number, unit, workMode == null ? null : new WorkMode(workMode), apartment == null ? new Integer[]{0} : apartment, personal == null ? new Integer[]{0} : personal, program, access, outer, dateOpenPlanFrom, dateOpenPlanTo, dateOpenFrom, dateOpenTo, dateAccessFrom, dateAccessTo, protectionEquipment  == null ? new Integer[]{0}: protectionEquipment, status, pageable);

询问

@Query("select a.id from DoseAssignment a where (:id is null or a.id=:id) and (:department is null or a.department=:department) and (:unit is null or a.unit=:unit) and (:workMode is null or a.workMode=:workMode) and (:program is null or :program=false and a.program is null or :program=true and a.program is not null) and (:dateOpenPlanFrom is null or a.dateOpenPlan>=:dateOpenPlanFrom) and (:dateOpenPlanTo is null or a.dateOpenPlan<=:dateOpenPlanTo) and (:dateOpenFrom is null or a.dateOpen>=:dateOpenFrom) and (:dateOpenTo is null or a.dateOpen<=:dateOpenTo) and (:status is null or a.status=:status) and (:access is null or :access=true and a.status=4 or :access=false and not a.status=4) and ((not 0 in :apartment or not 0 in :personal or :outer is not null or :dateAccessFrom is not null or :dateAccessTo is not null or not 0 in :protectionEquipment) and a.id in (select distinct ai.id from DoseAssignment ai left join ai.protectionEquipment pei left join ai.personal pi left join ai.apartment api left join ai.assignmentAccess aai where (:department is null or ai.department=:department) and (:unit is null or ai.unit=:unit) and (:workMode is null or ai.workMode=:workMode) and (:program is null or :program=false and ai.program is null or :program=true and ai.program is not null) and (:dateOpenPlanFrom is null or ai.dateOpenPlan>=:dateOpenPlanFrom) and (:dateOpenPlanTo is null or ai.dateOpenPlan<=:dateOpenPlanTo) and (:dateOpenFrom is null or ai.dateOpen>=:dateOpenFrom) and (:dateOpenTo is null or ai.dateOpen<=:dateOpenTo) and (:status is null or ai.status=:status) and (0 in :personal or pi.id in :personal) and (0 in :apartment or api.id in :apartment) and (0 in :protectionEquipment or pei.id in :protectionEquipment) and (:dateAccessFrom is null or aai.enterDate>=:dateAccessFrom) and (:dateAccessTo is null or aai.enterDate<=:dateAccessTo) and (:outer is null or :outer=true and pi.type=2 or :outer=false and a.id not in (select distinct aii.id from DoseAssignment aii left join aii.personal pii where pii.type=2))) or not (not 0 in :apartment or not 0 in :personal or :outer is not null or :dateAccessFrom is not null or :dateAccessTo is not null or not 0 in :protectionEquipment))")

.

Page<Integer> findId(@Param("department") Department department, @Param("id") Integer id, @Param("unit") Integer unit, @Param("workMode") WorkMode workMode, @Param("apartment") Integer[] apartment, @Param("personal") Integer[] personal, @Param("program") Boolean program, @Param("access") Boolean access, @Param("outer") Boolean outer, @Param("dateOpenPlanFrom") Date dateOpenPlanFrom, @Param("dateOpenPlanTo") Date dateOpenPlanTo, @Param("dateOpenFrom") Date dateOpenFrom, @Param("dateOpenTo") Date dateOpenTo, @Param("dateAccessFrom") Date dateAccessFrom, @Param("dateAccessTo") Date dateAccessTo, @Param("protectionEquipment") Integer[] protectionEquipment, @Param("status") Integer status, Pageable pageable);
java sql-server hibernate
2个回答
1
投票

datetime2类型的大小为6-8个字节(并包含日期的日期和时间部分)与一个1字节的tinyint,其值包含0-255。你不能将10磅的重量放入1盎司的容器中。


0
投票

错误给出了答案。 tinyintdatetime2是不相容的。如果你想将tinyint转换为datetime2,你需要首先将它转换为datetime(与tinyint兼容),然后再转换为datetime2

© www.soinside.com 2019 - 2024. All rights reserved.