Reputation: 48
I am using JPA through Hibernate in Spring. I need to process a lot of data in a @Transactional method. The process may take quite some time, so I want to query and display the progress on my front-end. "50 of 1000 items have been processed", etc.
But how can I commit the process status into DB during data is being processed within a @Transactional annotated method?
It may work by making a remote call, any other better ways?
Thanks in advance.
Upvotes: 0
Views: 1144
Reputation: 153730
You don't need a query for the update status. You can use JMS to push progress notifications so the UI can consume them while the transaction is still running (AJAX progress bar + a REST service which can consume the JMS updates).
If you don't want JMS you can use any other messaging technology for this task. You cam even use a Cache for setting the update progress and read it in some other thread.
You can even write your own mechanism backed by a java.util.concurrent blocking queue.
Bottom line, you don't need the db for monitoring the progress of that batch processing job.
Upvotes: 1
Reputation: 8146
I have found something from Here.
get TransactionStatus
using TransactionAspectSupport.currentTransactionStatus()
inject transaction manager to your bean (assuming you are using hibernate) try to invoke doCommit(DefaultTransactionStatus status)
in transaction manager.
try this out not sure it will work or not because as per spring doc Spring Doc
You are strongly encouraged to use the declarative approach to rollback if at all possible. Programmatic rollback is available should you absolutely need it, but its usage flies in the face of achieving a clean POJO-based architecture.
Upvotes: 0
Reputation: 1072
The @Transactional will commit once it finish all records it processes. So if you want to commit batch by batch, you have to call your db calling method as batch by batch.
Upvotes: 0