Hello Andrea, I have tried to remove the cascade PERSIST SpecialPricePoint wholesalePrice; and I still get the same behavior. In the sql logs I do not see any delete query for SpecialProductServiceWithoutCacheTest.shouldDeleteProduct . I also tried to remove the MERGE cascade but it did not change anything. Log extract for code :
SpecialProduct product = specialProductService.getProduct(provider, operatorId, wholesalePrice, productId);
assertThat(product).isNotNull();
specialProductService.deleteProduct(provider, operatorId, wholesalePrice, productId);
SpecialProduct product1 = specialProductService.getProduct(provider, operatorId, wholesalePrice, productId);
assertThat(product1).isNull();
log :
For information when same test is ran with L2 cache enabled we see the log below and the entity is successfully deleted.
Test only with hibernate and JPA I have tried to reproduced the test without springboot using the test case template using the same model classes and the following test
@Test
public void shouldDeleteProduct() {
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
String operatorId = "OPERATOR_1";
Provider provider = A;
SpecialOperator specialOperator = new SpecialOperator(provider, operatorId);
entityManager.persist(specialOperator);
String wholesalePrice = "1 EUR";
SpecialPricePoint specialPricePoint = new SpecialPricePoint(specialOperator, wholesalePrice);
entityManager.persist(specialPricePoint);
String productId = "PRODUCT_1";
SpecialProduct specialProduct = new SpecialProduct(productId, specialPricePoint);
entityManager.persist(specialProduct);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
SpecialPricePoint pricePoint = entityManager.find(SpecialPricePoint.class, new SpecialPricePointPK(new SpecialOperatorPK(provider, operatorId), wholesalePrice));
assertThat(pricePoint).isNotNull();
SpecialProduct product = entityManager.find(SpecialProduct.class, new SpecialProductPK(new SpecialPricePointPK(new SpecialOperatorPK(provider,
operatorId),
wholesalePrice),
productId));
assertThat(product).isNotNull();
entityManager.remove(product);
entityManager.getTransaction().commit();
entityManager.getTransaction().begin();
SpecialProduct product1 = entityManager.find(SpecialProduct.class, new SpecialProductPK(new SpecialPricePointPK(new SpecialOperatorPK(provider,
operatorId),
wholesalePrice),
productId));
assertThat(product1).isNull();
entityManager.getTransaction().commit();
entityManager.close();
}
This time I get an exception :
test case can be found in archive hibernate-orm-6-test.zip |