Reputation: 8042
If you have a database transaction that should be read only, do you commit or rollback? Is there any reason to do one or the other? Does one of the approachs improve database performance?
Upvotes: 4
Views: 1376
Reputation: 37374
Some RDMS (at least Oracle ) have READ ONLY isolation level. Otherwise, I prefer ROLLBACK
since it doesn't create an entry in transaction log (a bit better from performance point of view).
Update
Some explanations.
Most RDMS log all committed transactions and changes associated with transaction. Even if no changes are made, server logs a transaction. I don't see any points in wasting server resources by storing useless data.
Upvotes: 4
Reputation: 9574
I agree with Downpour046 I do the following for read only operations. Works like a charm, no issues.
Session session;
synchronized (this) {
session = currentSession();
Query rowResult = session.createSQLQuery(rowQuery).addEntity(table.getClass());
tableRow = rowResult.list().toArray();
}
public Session currentSession() {
Session s = (Session) session.get();
// Open a new Session, if this thread has none yet
if (s == null || !s.isOpen()) {
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
session.set(s);
}
return s;
}
Upvotes: 1