Erwan Moutymbo (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=640210c...
) *commented* on HHH-16946 (
https://hibernate.atlassian.net/browse/HHH-16946?atlOrigin=eyJpIjoiMjI2OG...
)
Re: Entity with a composite id using an @IdClass with a bidirectionnal @OneToOne not
deleted when L2 cache disabled (
https://hibernate.atlassian.net/browse/HHH-16946?atlOrigin=eyJpIjoiMjI2OG...
)
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();
// when
specialProductService.deleteProduct(provider, operatorId, wholesalePrice, productId);
// then
SpecialProduct product1 = specialProductService.getProduct(provider, operatorId,
wholesalePrice, productId);
assertThat(product1).isNull();
log :
[main] DEBUG org.hibernate.SQL [correlationid=] - select
s1_0.product_id,s1_0.operator_id,s1_0.provider_id,s1_0.wholesale_price_amount,w1_0.operator_id,w1_0.provider_id,o2_0.operator_id,o2_0.provider_id,o2_0.creation_date,o2_0.modification_date,w1_0.price_point,s1_0.creation_date,s1_0.modification_date
from special_products s1_0 join special_operator_prices_points w1_0 on
w1_0.operator_id=s1_0.operator_id and w1_0.provider_id=s1_0.provider_id and
w1_0.price_point=s1_0.wholesale_price_amount left join special_operators o2_0 on
o2_0.operator_id=w1_0.operator_id and o2_0.provider_id=w1_0.provider_id where
(s1_0.product_id,s1_0.operator_id,s1_0.provider_id,s1_0.wholesale_price_amount) in
((?,?,?,?))
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [1] as
[VARCHAR] - [PRODUCT_1]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [2] as
[VARCHAR] - [OPERATOR_1]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [3] as
[VARCHAR] - [A]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [4] as
[VARCHAR] - [1 EUR]
[main] INFO o.h.e.i.StatisticalLoggingSessionEventListener [correlationid=] - Session
Metrics {
11477 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
22589 nanoseconds spent preparing 1 JDBC statements;
92890 nanoseconds spent executing 1 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
502819 nanoseconds spent executing 1 flushes (flushing a total of 3 entities and 1
collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0
collections)
}
[main] DEBUG org.hibernate.SQL [correlationid=] - select
s1_0.product_id,s1_0.operator_id,s1_0.provider_id,s1_0.wholesale_price_amount,w1_0.operator_id,w1_0.provider_id,o2_0.operator_id,o2_0.provider_id,o2_0.creation_date,o2_0.modification_date,w1_0.price_point,s1_0.creation_date,s1_0.modification_date
from special_products s1_0 join special_operator_prices_points w1_0 on
w1_0.operator_id=s1_0.operator_id and w1_0.provider_id=s1_0.provider_id and
w1_0.price_point=s1_0.wholesale_price_amount left join special_operators o2_0 on
o2_0.operator_id=w1_0.operator_id and o2_0.provider_id=w1_0.provider_id where
(s1_0.product_id,s1_0.operator_id,s1_0.provider_id,s1_0.wholesale_price_amount) in
((?,?,?,?))
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [1] as
[VARCHAR] - [PRODUCT_1]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [2] as
[VARCHAR] - [OPERATOR_1]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [3] as
[VARCHAR] - [A]
[main] TRACE org.hibernate.orm.jdbc.bind [correlationid=] - binding parameter [4] as
[VARCHAR] - [1 EUR]
[main] INFO o.h.e.i.StatisticalLoggingSessionEventListener [correlationid=] - Session
Metrics {
9368 nanoseconds spent acquiring 1 JDBC connections;
0 nanoseconds spent releasing 0 JDBC connections;
664893 nanoseconds spent preparing 1 JDBC statements;
182485 nanoseconds spent executing 1 JDBC statements;
0 nanoseconds spent executing 0 JDBC batches;
0 nanoseconds spent performing 0 L2C puts;
0 nanoseconds spent performing 0 L2C hits;
0 nanoseconds spent performing 0 L2C misses;
0 nanoseconds spent executing 0 flushes (flushing a total of 0 entities and 0
collections);
0 nanoseconds spent executing 0 partial-flushes (flushing a total of 0 entities and 0
collections)
}
org.opentest4j.AssertionFailedError:
expected: null
but was: SpecialProduct(productId=PRODUCT_1,
wholesalePrice=SpecialPricePoint(operator=SpecialOperator(provider=A,
operatorId=OPERATOR_1), wholesalePrice=1 EUR))
For information when same test is ran with L2 cache enabled we see the log below and the
entity is successfully deleted.
delete from special_products where product_id=? and operator_id=? and provider_id=? and
wholesale_price_amount=? and creation_date=?
--------------------------------
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();
// Do stuff...
// given
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();
// when
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();
// Then
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 :
jakarta.persistence.RollbackException: Error while committing the transaction
at
org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:65)
at
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104)
at org.hibernate.bugs.JPAUnitTestCase.shouldDeleteProduct(JPAUnitTestCase.java:68)
...
Caused by: org.hibernate.exception.DataException: could not execute statement [La
paramètre "#5" n'est pas initialisé
Parameter "#5" is not set; SQL statement:
delete from SPECIAL_PRODUCTS where PRODUCT_ID=? and OPERATOR_ID=? and PROVIDER_ID=? and
WHOLESALE_PRICE_AMOUNT=? and PRODUCT_ID=? and OPERATOR_ID=? and PROVIDER_ID=? and
WHOLESALE_PRICE_AMOUNT=? and CREATION_DATE=? [90012-220]] [delete from SPECIAL_PRODUCTS
where PRODUCT_ID=? and OPERATOR_ID=? and PROVIDER_ID=? and WHOLESALE_PRICE_AMOUNT=? and
PRODUCT_ID=? and OPERATOR_ID=? and PROVIDER_ID=? and WHOLESALE_PRICE_AMOUNT=? and
CREATION_DATE=?]
at
org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:53)
at
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:56)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:108)
at
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:278)
at
org.hibernate.engine.jdbc.mutation.internal.AbstractMutationExecutor.performNonBatchedMutation(AbstractMutationExecu
...
test case can be found in archive hibernate-orm-6-test.zip
(
https://hibernate.atlassian.net/browse/HHH-16946#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16946#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100232- sha1:304e1c7 )