1
如何重寫的標準如何重寫JPA標準原生查詢
@Query(value = "select count(*), hicn.name \n" +
"from \n" +
" table1 cid, \n" +
" table2 hicn \n" +
"where TRUNC(cid.CREATED_WHEN) = TRUNC(?) \n" +
" and hicn.ID = cid.ID\n" +
"group by hicn.name", nativeQuery = true)
,並把結果在DTO查詢?
public class DataDto {
private String name;
private Long count;
public DataDto(String name, Long count) {
this.name = name;
this.count = count;
}
}
實體爲例。實體大,爲了方便而減小。你能用「加入」和「和」來展示解決方案嗎?主要的問題是我不明白如何訪問兩個表並使用標準從它們獲取數據。
對於表1
@Data
@Entity
@Table(name = "TABLE_ONE")
public class TableOneModel {
@Id
@Column(name = "TAB_ONE_ID")
private Long tabOneId;
@Column(name = "CREATED_WHEN")
private Date createdWhen;
}
對於表2
@Data
@Entity
@Table(name = "TABLE_TWO")
public class TableTwoModel {
@Id
@Column(name = "TAB_TWO_ID")
private Long tabTwoId;
@Column(name = "NAME")
private String name;
}
沒有解決方案。但是,在不需要的查詢中刪除'\ n' – Jens
顯示 – Jens
表中的實體添加了我的實體。 – kel