I'm using Hibernate and Warp Persistence and I am running many
"stand-alone" transactions (>20.000) in one unit of work.
This causes performance problems since it seems like the Hibernate
session isn't cleared after each transaction so all updated entities
remain in the session.
How am I supposed to solve this by using Warp Persistence?
Is there a way to clear the session for each transaction or something like that?
Pseudo code:
final WorkManager unitOfWork;
runJob() {
unitOfWork.beginWork();
orderUpdates = readOrderUpdatesFromFile();
for (OrderUpdate orderUpdate : orderUpdates) {
updateOrder(orderUpdate);
}
unitOfWork.endWork();
}
@Transactional
updateOrder(OrderUpdate orderUpdate) {
// Get order from db, update and store it
};
Very thankful for help.
Best regards,
Gösta
Pseudo code (I'm using Guice) of my solution:
@Inject
public JobRunner(EntityManager entityManager) {};
final WorkManager unitOfWork;
runJob() {
unitOfWork.beginWork();
orderUpdates = readOrderUpdatesFromFile();
for (OrderUpdate orderUpdate : orderUpdates) {
updateOrder(orderUpdate);
entityManager.clear();
}
unitOfWork.endWork();
}
@Transactional
updateOrder(OrderUpdate orderUpdate) {
// Get order from db, update and store it
};
2010/11/26 Gösta Jonasson <gos...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "warp-core" group.
To post to this group, send email to warp...@googlegroups.com.
To unsubscribe from this group, send email to warp-core+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/warp-core?hl=en.
Yes, the L1 cache is getting too big, that's the problem.
I guess the @Transactional does a call to flush() after the method so
that's not a problem.
Clearing the persistence context/session after each transaction works
perfect but it would be nicer if it were an optional part of Warp.
It seems like this use case, one job that does a lot of transactions,
would be quite common.
Just one last question: How would you solve this?
* By creating a new unit of work/session for each order that should be
processed (with one transaction inside).
* "Batching" let's say 1000 order changes per unit of work/session
(with one transaction per order).
* Having one long unit of work/session and clearing it after each
transaction (with one transaction per order) as I'm doing now.
Thanks for your help.
/Gösta