on 2018 Mar 05 1:46 PM
Hi there. I am running something like:
@Transactional
void removeProducts(List<ProductModel> products) {
modelService.removeAll(products);
System.out.println("Right after removing");
}
The list contains many products, among them a product with code 1234.
To test the transaction I am making my debugger pause the thread on the "System.out". While the debugger is paused there, I go to MySQL and run something like this:
UPDATE products SET p_code = '1234' WHERE p_code = '1234';
That update should be waiting for the running transaction to end, but that's not the case. Instead the update runs inmediately.
I have tried the same but intead the @Transactional annotation I wrote it this way:
@Transactional
void removeProducts(List<ProductModel> products) {
Transaction tx = Transaction.current();
try {
tx.begin();
modelService.removeAll(products);
System.out.println("Right after removing");
} catch (Exception ex) {
tx.rollback();
} finally {
tx.commit();
}
}
This time, trying to update the product from mysql while the transaction was running made mysql wait until the transaction was completed.
I have also tried adding the annotation in this way:
@Transactional(propagation=Propagation.REQUIRES_NEW, isolation=SERIALIZABLE)
void removeProducts(List<ProductModel> products) { ... }
But didn't make any difference (yep, the isolation mode goes to READ_COMMITED anyway).
One more thing, the documentation mentions that Spring @Transaction should be used. Maybe I am missing something but I only know of @Transactional in Spring.
Can somebody confirm that @Transactional is ignored, at least for MySQL from Hybris 6.3.9.5?
Cheers,
Carlos
Request clarification before answering.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.