adamsaghy commented on code in PR #3854:
URL: https://github.com/apache/fineract/pull/3854#discussion_r1559279265
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/account/service/AccountAssociationsReadPlatformServiceImpl.java:
##########
@@ -18,86 +18,101 @@
*/
package org.apache.fineract.portfolio.account.service;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import static java.util.stream.Collectors.toList;
+
+import com.querydsl.core.Tuple;
+import com.querydsl.core.types.dsl.BooleanExpression;
+import com.querydsl.core.types.dsl.SimpleExpression;
+import com.querydsl.jpa.impl.JPAQuery;
+import jakarta.persistence.EntityManager;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.portfolio.account.data.AccountAssociationsData;
import org.apache.fineract.portfolio.account.data.PortfolioAccountData;
import org.apache.fineract.portfolio.account.domain.AccountAssociationType;
+import org.apache.fineract.portfolio.account.domain.QAccountAssociations;
import org.apache.fineract.portfolio.loanaccount.domain.LoanStatus;
+import org.apache.fineract.portfolio.loanaccount.domain.QLoan;
+import org.apache.fineract.portfolio.savings.domain.QSavingsAccount;
import org.apache.fineract.portfolio.savings.domain.SavingsAccountStatusType;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
@RequiredArgsConstructor
@Slf4j
public class AccountAssociationsReadPlatformServiceImpl implements
AccountAssociationsReadPlatformService {
- private final JdbcTemplate jdbcTemplate;
+ private final EntityManager entityManager;
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
I dont really understand the new transaction for reading... I believe you
are referring to Optimistic read locking but I am afraid you are failing to
sort the explained problem by this.
If I understand the problem you are explaining in the description of the PR
is the following:
Transaction isolation= READ COMMITTED
TX1 started
- Read Account (by name) -> Account (id=1, name=Adam, version=1, ref=1234)
TX2 started
- Read Account (by id) -> Account (id=1, name=Adam, version=1, ref=1234)
- Modify Account name -> Account (id=1, name=Josh, version=**2**,
ref=**3456**)
TX2 ended
TX1:
- Read Accounts -> [Account(id=1, name=Josh, version=2)] -> JPA realize with
the same ID a modified entry it has in its persistence context, so it is not in
sync with the DB anymore and trigger Optimistic lock!
Imagine if you are reading the entity in new transactions when the read
completed, the read entity became detached and removed from the persistence
context and the JPA optimistic locking would only be triggered if this detached
entity to be written back to the DB, but not when it was read again...
What do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]