java - Benefits of using Springs Transaction management vs using hibernate -


i've been trying learn spring , hibernate, , i've used lot of examples around net put nice application. however, realized spring supports transaction management. in spring app made whatever calls wanted to, directly hibernate. there reason/benefit why people use spring's transaction management/db stuff?

the real advantages are:

  • lightweight declarative syntax. compare:

    public void saveemployee(employee e) {     session s = sf.getcurrentsession();         s.gettransaction().begin();     s.save(e);         s.gettransaction().commit(); } 

    and

    @transactional public void saveemployee(employee e) {     sf.getcurrentsession().save(e); } 
  • flexible transaction propagation. imagine need execute saveemployee() method part of complex transaction. manual transaction management, need change method since transaction management hard-coded. spring, transaction propagation works smoothly:

    @transactional public void hireemployee(employee e) {     dao.saveemployee(e);     dootherstuffinthesametransaction(e); } 
  • automatic rollback in case of exceptions


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -