【发布时间】: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