in Education by
I have a @Stateless-Bean which performs some Database operations in a single method public void doOperation(){ User u1 = createNewUser() User u2 = createNewUser() User updated = mergeUser(u1,u2) // just as an example // should write to database now! otherBlockingOperation() } However the changes are not visible in the database until the blocking operation finished and therefore not visible in the frontend. I thought this is because the transaction is not committed until otherBlockingOperation() is finished. I then wrapped otherBlockingOperation() in a Thread, which did not work again. However I think the real problem is merge which will only update the entity after the method is done. How can I change the values of Object instantly? Edit: @PersistanceContext private EntityManager em; mergeUser(T entity){ em.merge(entity); em.flush(); } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Depending on the actual business requirements, a possible solution would be to move the otherBlockingOperation() method to a new @Stateless bean and mark the method as @Asynchronous @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW). This will effectively run the method in a new thread and new transaction. You would simply @Inject the new bean and call the otherBlockingOperation() method. A new transaction might (or might not) be a valid option, depending on business needs (i.e. the new transaction might fail, while the original transaction might succeed). However, the update will be committed in DB sooner (but still after the original transaction is committed) without dependency on the otherBlockingOperation() process (or even successful commit).

Related questions

0 votes
    I have a @Stateless-Bean which performs some Database operations in a single method public void doOperation() ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm trying to make sure that all my threads of Class A have finished before notify is called. At ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    For a transaction to be durable, its changes need to be written to ________ storage. (a) Volatile storage ... , Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    I am new to spring, as part of my project implementation, I am supposed to add a spring retry on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I am new to spring, as part of my project implementation, I am supposed to add a spring retry on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    What is not true in context of HTML tag ? O Table cell changes its width automatically based on content O We can ... table border is o Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    State true or false. When you have finished your work in the IMG or ABAP Workbench, or have reached a certain stage, you can release the request. A. True B. False...
asked Feb 20, 2023 in Technology by JackTerrance
0 votes
    This question already has answers here: Quick-and-dirty way to ensure only one instance of a shell script ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    If you connect to a database or a file in a program you should always __________ it when you’re finished using it. Select the correct answer from above options...
asked Dec 23, 2021 in Education by JackTerrance
0 votes
    My problem is the same as described in [1] or [2]. I need to manually set a by default auto- ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    Is there any way to stop a SQL Azure DB so that it doesn't charge anything towards our account? I don't ... cloud services and VM's. Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
...