I'm using Spring annotations to manage my transactions like so:
@Transactional(readOnly = true)
public class AlertServiceImpl implements AlertService {
private AlertDAO alertDAO;
public List<Alert> getAlerts(){
List<Alert> alerts = alertDAO.getAlerts();
return alerts;
}
}
I'm wondering what happens if I forget the annotation:
// Oops! Forgot to use transactional annotation
public class AlertServiceImpl implements AlertService {
private AlertDAO alertDAO;
public List<Alert> getAlerts(){
List<Alert> alerts = alertDAO.getAlerts();
return alerts;
}
}
When the alertDAO implementation is following:
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
// no annotation here either
public class HibernateAlertDAO extends HibernateDaoSupport implements AlertDAO {
public List<Alert> getAlerts(){
// some implementation details that define queryString
Query query = getSession().createQuery(queryString);
List<Alert> alerts = query.list();
return alerts;
}
}
It seems like Hibernate allows me to fetch data from database even without the annotation.
What are the consequences of this kind of carelessness and what are the worst case scenarios that could happen?
See Question&Answers more detail:os