我需要删除LastTransactionServiceAmount(子)记录,这些记录的LastTransaction(父)对象的msisdn值等于某个值。 的 LastTransactionServiceAmount.java
@Entity
public class LastTransactionServiceAmount {
private long lastTransactionServiceAmountId;
private LastTransaction lastTransaction;
private int serviceId;
private long amount;
@ManyToOne
@JoinColumn(name = "lastTransactionId")
public LastTransaction getLastTransaction() {
return lastTransaction;
}
}
LastTransaction.java
@Entity
public class LastTransaction {
private long lastTransactionId;
private long transactionId;
private long tariffId;
private long taxId;
private int planId;
private String msisdn;
private Date dateTime;
private String channel;
private Set<LastTransactionServiceAmount> lastTransactionServiceAmounts;
@OneToMany(mappedBy = "lastTransaction")
public Set<LastTransactionServiceAmount> getLastTransactionServiceAmounts() {
return lastTransactionServiceAmounts;
}
}
LastTransactionServiceAmountRepo.java
public interface LastTransactionServiceAmountRepo extends
CrudRepository<LastTransactionServiceAmount, Long> {
@Transactional
@Modifying
@Query("DELETE FROM LastTransactionServiceAmount lts WHERE lts.lastTransaction.msisdn = ?1")
void deleteByMsisdn(String msisdn);
}