我有两个实体。一个是 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
}
如果匹配表的状态发生更改,则这些行将被插入 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 查询不起作用。请建议我将插入的行从 MatchTable 更改为 MatchLog 的JPQL查询。
答案 0 :(得分:1)
除非我弄错了,否则JPA不支持“插入select”。您可以更改为本地查询。