java My JPA Repository请求正在返回缓存,而我没有在Spring Boot中启用它
我需要帮助,因为我正在按顺序执行3个查询,但是Spring和JPA正在不同的对象上应用缓存
子对象建立在内存中返回相同的结果,但在每个对象“食物、药物和附件”中,我必须对该子对象进行不同的更改,但当我更改它时,它似乎是作为参考的,也就是说,我以一种方式更改它,并在其他对象中复制
Establishment obj = establishmentService.findById(id);
List<EstablishmentProduct> food = repo.findByEstablishmentAndProductSegment(obj, SegmentEnum.FOOD.getCod());
List<EstablishmentProduct> medication = repo.findByEstablishmentAndProductSegment(obj, SegmentEnum.MEDICATION.getCod());
List<EstablishmentProduct> accessories = repo.findByEstablishmentAndProductSegment(obj, SegmentEnum.ACCESSORIES.getCod());
我的实体
@Entity
public class EstablishmentProduct implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String description;
private Integer status;
private Integer quantity;
private Double value;
private Integer productSegment;
private boolean deleted = false;
@ManyToOne(cascade = CascadeType.DETACH)
@JoinColumn(name = "product_id")
private Product product;
@JsonIgnore
@ManyToOne()
@JoinColumn(name = "establishment_id")
private Establishment establishment;
@Repository
public interface EstablishmentProductRepository extends JpaRepository<EstablishmentProduct, Integer> {
List<EstablishmentProduct> findByEstablishmentAndProductSegment(Establishment establishment, Integer productSegment);
Guys,正如实体正在进行的查询一样,已经通过机构ID进行了测试,并返回实体机构的子类的相同指针
建立对象=建立服务。findById(id)强>
在我看来,Spring和JPA正在应用一个我没有请求的缓存,我希望对于每个findByEstablishmentAndProductSegmentne,它将返回新的子对象,而不带缓存
我已经以各种方式禁用了缓存,但没有任何效果
我知道机构对象不会更改,但产品对象会更改,但正如我提到的,我需要为返回的每个细分对机构进行更改
你能帮我吗
# 1 楼答案
您看到的是JPA一级缓存的效果,它不能被禁用。但是,您可以从
EntityManager
中删除部分或所有实体,或者启动一个新会话,该会话将以空缓存开始