-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I want to do a countribution where methods with batch keywords are processed through the persistence context. #3360
Comments
Would you mind providing some pseudo-code that explains what you want to achieve? We currently have a difficult time understanding what you're up to. |
I'm not familiar with English, so I used a translator to leave an issue. So the writing can be a little awkward. First of all, I'll tell you about the code that made me think of contribution with an example. @SpringBootTest
class MemberRepositoryTest {
@Autowired
private MemberRepository memberRepository;
@BeforeEach
public void setUp() {
for (int i = 0; i < 10; i++) {
memberRepository.save(Member.builder()
.clubName("test" + i)
.build());
}
}
@Test
@DisplayName("PostRemove is invoked when deleting using deleteAll.")
public void deleteAllTest() {
memberRepository.deleteAll();
}
} And if you delete it using the method with the @SpringBootTest
class MemberRepositoryTest {
@Autowired
private MemberRepository memberRepository;
@BeforeEach
public void setUp() {
for (int i = 0; i < 10; i++) {
memberRepository.save(Member.builder()
.clubName("test" + i)
.build());
}
}
@Test
@DisplayName("PostRemove is not invoked when deleting using DeleteAll.")
public void deleteAllInBatchTest() {
memberRepository.deleteAllInBatch();
}
} And the pseudocode of what I suggest is as follows. (I wrote the pseudocode based on the
function deleteAllInBatch() {
Create a query string using the result of the getDeleteAllQueryString() method
Create a Query object from the EntityManager
Apply query hints
// Suggestion start
if (Type parameter T exists in Persistence Context)
Delete all type parameters T present in the entity manager.
// Suggestion end
Execute the query
}
function deleteAllInBatch(entities: Iterable<T>) {
Check if the 'entities' parameter is not null
if (Check if 'entities' has elements) {
Construct the delete query string using entity name
Apply query and bind parameters using QueryUtils
// Suggestion start
if (Type parameter T exists in Persistence Context)
Delete parameters T present in the entity manager.
// Suggestion end
Execute the delete query
}
}
function deleteAllByIdInBatch deleteByIds(Iterable<ID> ids) {
Check if 'ids' parameter is not null
if (Check if 'ids' has elements) {
if (Check if the entity has a composite ID) {
For entities with composite ID, fetch references and delete all in batch
// If the deleteAllInBatch code is modified as I suggested, there is no need to modify the code here.
} else {
Construct the delete query string
Construct the delete query object
Set parameter 'ids' based on the type of 'ids' (Collection or other)
Apply query hints and execute the delete query
// Suggestion start
if (Type parameter T exists in Persistence Context)
Delete parameters present in the entity manager.
// Suggestion end
Execute the delete query
}
}
} |
There was a typo in pseudocode. Methods with parameters( |
Hello, I'm inquiring about any updates on this issue, please review it, thank you. |
While looking for query optimization, I learned about the Batch keyword provided by Data JPA. And I also learned that the performance varies depending on the presence or absence of the Batch keyword. However, when adding the Batch keyword, I found that the "IN" keyword sends the query at once, but it processes it without going through the persistence context.
In response, I thought it would be good to modify the code so that methods with the Batch keyword are processed through the persistence context. If my idea feels valid, can I do a countribution on this?
The text was updated successfully, but these errors were encountered: