试图在春季启动olingo odatav2服务上使用日期进行筛选,但出现gregorian日历错误



我正在尝试做一个类似的过滤请求

<Service>/odata/InspectionValidations?$filter=DateAssigned gt datetime'2020-07-23T00:00:00'

但是我得到了

java.util.GregorianCalendar cannot be cast to java.util.Date

事实上,大约一年前也有一个类似的问题,这里没有答案,所以我要发布一个新的问题。我想我需要某种转变?或者我声明DateAssigned实体错误了?在本例中,我使用了java.util.Date,但将其更改为java.sql.Date会导致相同的错误,因为sql。Date只是util的一个子类。日期

package gov.doe.app.domain;
import java.util.Date;
//import java.sql.Date;
import java.time.LocalDateTime;
import java.util.GregorianCalendar;
import com.fasterxml.jackson.annotation.JsonFormat;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.persistence.SequenceGenerator;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
@Entity
@Table(name = "inspection_validation")
public class InspectionValidation {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, 
generator = "inspection_validation_id_seq")
@SequenceGenerator(name = "inspection_validation_id_seq", 
sequenceName = "seq_inspection_validation", allocationSize = 1)
@Column(name = "id")
@NotNull
private Long id;
@Column(name = "version")
@NotNull
private Long version;
@Column(name = "is_active")
@NotNull
private Boolean isActive;
//@Column(name = "assigned_by")
//private Long assignedBy;
@ManyToOne
@JoinColumn(name = "assigned_by", referencedColumnName = "id")
private AdminAccount assignedBy;
@Column(name = "assigned_remarks")
private String assignedRemarks;
@Column(name = "assignment_no")
@NotNull
private String assignmentNumber;
@Column(name = "contact_no")
private String contactNumber;
//@Column(name = "current_evaluator")
//private Long currentEvaluator;
@ManyToOne
@JoinColumn(name = "current_evaluator", referencedColumnName = "id")
private AdminAccount currentEvaluator;
@Column(name = "date_assigned")
private Date dateAssigned;
@Column(name = "evaluation_remarks")
private String evaluationRemarks;
}

我正在使用ODataJPAServiceFactory来处理Odata部分。

解决方案是使用java.sql.Date在实体定义中定义数据。

您还可以决定使用以下SQL数据类型之一来满足您的需求

DATE保存没有时间信息的日期

TIME存储没有日期的时间和

TIMESTAMP,用于存储日期和时间信息。

我也遇到了同样的问题。使用import java.util.Calendar;而不是import java.util.Date;

相关内容

  • 没有找到相关文章

最新更新