【问题标题】:JPQL Insert by selecting query not working通过选择查询不起作用的 JPQL 插入
【发布时间】:2019-09-07 14:15:07
【问题描述】:

我有两个下面的实体。一个是MatchTable,另一个是MatchLog

@Entity
public class MatchTable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;

    @ManyToOne
    private Integer primaryID;

    @ManyToOne
    private Integer suspectedID;

    @Column(nullable=false)
    private Integer status;

    //getter and setter

}



@Entity
public class MatchLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;

    @OneToOne
    private MatchTable referenceID;

    @Column(nullable=false)
    private Long primaryID;

    @Column(nullable=false)
    private Long suspectedID;

    @Column(nullable=false)
    private Integer status;

    //getter and setter
}

如果MatchTable状态发生变化,这些行将被插入到MatchLog中。我已尝试使用以下 JPQL 查询。

@Query("INSERT INTO MatchLog (referenceID.id,primaryID,suspectedID,status) SELECT id,primaryID,suspectedID,status from MatchTable where (primaryID = :ID or suspectedID = :ID)")
int updateMatchLogTable(@Param("ID") long ID);

但是这个 JPQL 查询不起作用。请建议我将 insert 行从 MatchTable 更改为 MatchLog 的 JPQL 查询是什么。

【问题讨论】:

    标签: spring spring-boot jpa jpql


    【解决方案1】:

    除非我弄错了,否则 JPA 不支持“插入选择”。您可以更改为本机查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-02-25
      • 2016-08-11
      • 1970-01-01
      • 2011-01-17
      • 2017-09-17
      • 2017-08-14
      • 2014-03-22
      • 1970-01-01
      相关资源
      最近更新 更多