MySQL内部联接错误:在执行查询期间检测到为空。主键不得包含null

时间:2019-05-11 16:28:01

标签: java mysql jpa inner-join nativequery

我想关联两个表上的特定列,并基于时间戳(即同时发生但写在两个单独的表上的事件)获取匹配值。我正在使用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中查询的响应看起来不错:

table inner join resuktset

但是,我想将结果写到另一个表中。由于我不精通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.

1 个答案:

答案 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 []列表,此列表随后需要处理。