【发布时间】:2021-12-31 01:34:57
【问题描述】:
将命名查询定义为SELECT mdl FROM tbl_slots mdl where mdl.test_date between :dt and :dt order by mdl.test_time asc的实体
如果在查询中使用* 而不是mdl,JPA 会给出错误unexpected token: *
如果在 select 语句中提到列名,它会返回实体,其中各个字段填充了预期值
[{ “srNo”:1, “testDate”:“2021 年 12 月 30 日”, "testTime": "09:00-10:00", },{ “srNo”:2, “testDate”:“2021 年 12 月 30 日”, "testTime": "11:00-12:00", }]
如何在不提及列名的情况下在 select 语句中获得相同的结果,就像使用 *?
select * from table 查询的有效 JPQL 或 HQL 是什么?
实体类
@Table(name = "tbl_slots")
@NamedQueries({
@NamedQuery(name="slots",query = "SELECT mdl FROM tbl_slots mdl where mdl.test_date between :dt and :dt order by mdl.test_time asc")
})
public class TblSlots implements Serializable {
private Long srNo;
private Date testDt;
private String testTime;
public TblSlots() {}
public TblSlots(Long srNo, Date testDt, String testTime) {
this.srNo = srNo;
this.testDt = testDt;
this.testTime = testTime;
}
@Id
@Column(name = "sr_no", unique = true, nullable = false, precision = 16, scale = 0)
public Long getSrNo() {
return this.srNo;
}
public void setSrNo(Long srNo) {
this.srNo = srNo;
}
@Temporal(TemporalType.DATE)
@Column(name = "test_date", nullable = false, length = 13)
public Date getTestDt() {
return this.testDt;
}
public void setTestDt(Date testDt) {
this.testDt = testDt;
}
@Column(name = "test_time", nullable = false, length = 20)
public String getTestTime() {
return this.testTime;
}
public void setTestTime(String testTime) {
this.testTime = testTime;
}
【问题讨论】:
标签: java spring-boot hibernate spring-data-jpa orm