0
我無法更新實體,因爲沒有更改,但我需要更新其列已更新 o用作跟蹤列。即使沒有變化,我也希望更新自動更新的實體列。Spring JPA /休眠 - 如何更新對象未修改
實體
@Column(name = "UPDATED" , nullable = true)
@DateTimeFormat(iso = ISO.DATE_TIME)
private LocalDateTime updated;
@PreUpdate
public void updatedEntry(){
this.updated = LocalDateTime.now();
}
春天JPA庫
@Repository
public interface ProductRepository extends PagingAndSortingRepository<Product, BigDecimal>
{}
而下面的代碼是我更新值雖然有時對象將不會修改,因爲檢索到的值是相同的。
product.setBarcode(clfProduct.getBarcode());
product.setTaxcode(clfProduct.getTaxcode());
product.setPrice(clfProduct.getPrice());
product.setMinOrder(clfProduct.getMinOrder());
product.setMsrpPrice(clfProduct.getMsrpPrice());
product.setStock(stock);
productRepository.save(product);
我試圖避免這種方式,但我想這是沒有辦法。謝謝 –