Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. private static final ThreadLocal threadSession = new ThreadLocal();
  2. private static final ThreadLocal threadTransaction = new ThreadLocal();
  3.  
  4. public GenericDao(final Class<T> objectClass) {
  5. this.objectClass = objectClass;
  6. }
  7.  
  8. public Class<T> getObjectClass() {
  9. return this.objectClass;
  10. }
  11.  
  12. public T save(final T object) throws HibernateException {
  13. try {
  14. final Session s = this.getSessionHibernate();
  15. s.beginTransaction();
  16. s.save(object);
  17. s.getTransaction().commit();
  18. s.flush();
  19.  
  20. return object;
  21. } catch (final HibernateException ex) {
  22. GenericDao.logger.error(ex);
  23.  
  24. Session s = this.getSessionHibernate();
  25. s.getTransaction().rollback();
  26. s.clear();
  27.  
  28. throw new HibernateException(ex);
  29. }
  30. }
  31.  
  32. public void update(final T object) throws HibernateException {
  33. try {
  34. final Session s = this.getSessionHibernate();
  35. s.update(object);
  36.  
  37. } catch (final HibernateException ex) {
  38. GenericDao.logger.error(ex);
  39.  
  40. Session s = this.getSessionHibernate();
  41. s.getTransaction().rollback();
  42. s.clear();
  43.  
  44. throw new HibernateException(ex);
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement