我無(wú)法使用以下查詢(xún)從兩個(gè)表中獲取所有記錄我已經(jīng)嘗試過(guò)了,但我只從一張桌子上得到結(jié)果。我想要兩個(gè)表的結(jié)果,即 client_software_param_mapping 和 client_file_configuration 具有相同的 ClientId,這是從第三個(gè) pojo(client_software_configuration) 到第一個(gè)和第二個(gè) pojo 的外鍵。public Result showClientConfiguration() {EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("defaultPU"); EntityManager entityManager = entityManagerFactory.createEntityManager();Query q=entityManager. createQuery("SELECT c FROM client_software_param_mapping c JOIN fetch client_file_configuration f ON c.ClientId=f.ClientId"); List data =q.getResultList(); return ok(Json.toJson(data));}第一個(gè)pojo@Entitypublic class client_file_configuration { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; private String sourceFolder; private String sourceFile; private String processingFolder; private String processingFile; private String processedFolder; private int intervalInMin; private String readAfterDelay; private String parserClass; private String directoryMode; private String fileMode; private String actionMode; private String type; private String fileExpressionResolver; @OneToOne @JoinColumn(name = "ClientId") private client_software_configuration clientSoftwareConfiguration; public client_software_configuration getClientSoftwareConfiguration() { return clientSoftwareConfiguration; } public void setClientSoftwareConfiguration(client_software_configuration clientSoftwareConfiguration) { this.clientSoftwareConfiguration = clientSoftwareConfiguration; }}
1 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
這是正確的查詢(xún),因?yàn)樗祷卦?ClientId 處存在的第三個(gè) pojo 的對(duì)象,因此它能夠理解 ClientId 的類(lèi)型。JPQL 從不使用表名和列名。它總是使用實(shí)體名稱(chēng)及其映射的字段/屬性名稱(chēng)。所以在這里我采用了第三個(gè) pojo 的對(duì)象,該對(duì)象具有 ClientId 字段。
從 client_file_configuration c,client_software_param_mapping p 中選擇 c,p 其中 c.clientSoftwareConfiguration = p.clientSoftwareConfiguration
添加回答
舉報(bào)
0/150
提交
取消