我想关联两个表上的特定列,并基于时间戳(即同时发生但写在两个单独的表上的事件)获取匹配值。我正在使用MYSQL INNER JOINS
,如下所示:
到目前为止,我的查询如下:
String threatQueryJoin = "SELECT awsevents.ALERT.resourceName, awsevents.RECORD.Record_Id,awsevents.RECORD.resourceName, "
+ "awsevents.ALERT.alert_id FROM awsevents.ALERT inner join awsevents.RECORD on awsevents.ALERT.resourceName "
+ "= awsevents.RECORD.resourceName where (awsevents.ALERT.timeStamp >= '2019-05-10' AND awsevents.RECORD.timeStamp >= '2019-05-10') "
+ "AND (awsevents.ALERT.resourceName='company-checker-log-963f5e78-0dea-46f1-9a48-5a116bdae350' "
+ "AND awsevents.RECORD.resourceName='company-checker-log-963f5e78-0dea-46f1-9a48-5a116bdae350') order by awsevents.RECORD.timeStamp";
Query q = AWSEventsDAO.em.createNativeQuery(threatQueryJoin);
List ll = q.getResultList();
MySQL workbench
中查询的响应看起来不错:
但是,我想将结果写到另一个表中。由于我不精通MySQL
,因此很高兴知道是否有更好的方法来处理此类查询。使用inner join
时,出现以下错误:
Exception Description: The primary key read from the row [ArrayRecord(
=> company-checker-log-963f5e78-0dea-46f1-9a48-5a116bdae350
=> 45167
=> company-checker-log-963f5e78-0dea-46f1-9a48-5a116bdae350
=> 8108)] during the execution of the query was detected to be null. Primary keys must not contain null.
答案 0 :(得分:0)
我通过删除"users": {
"1": {
"id": 1,
"name": "John",
"email": "john@doe.com",
"supplier_id": 1,
"supplier_name": [
"Supplier1"
],
"supplier_code": "SUP001",
"count": "21",
"suppliers: 3
}
}
即mapped class
并使用
Record.class
,如Object[] alert = threatList.get(i);
和jpa
上的这些tutorials所示。事实证明,native querries
返回了一个Object []列表,此列表随后需要处理。