Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static final ThreadLocal threadSession = new ThreadLocal();
- private static final ThreadLocal threadTransaction = new ThreadLocal();
- public GenericDao(final Class<T> objectClass) {
- this.objectClass = objectClass;
- }
- public Class<T> getObjectClass() {
- return this.objectClass;
- }
- public T save(final T object) throws HibernateException {
- try {
- final Session s = this.getSessionHibernate();
- s.beginTransaction();
- s.save(object);
- s.getTransaction().commit();
- s.flush();
- return object;
- } catch (final HibernateException ex) {
- GenericDao.logger.error(ex);
- Session s = this.getSessionHibernate();
- s.getTransaction().rollback();
- s.clear();
- throw new HibernateException(ex);
- }
- }
- public void update(final T object) throws HibernateException {
- try {
- final Session s = this.getSessionHibernate();
- s.update(object);
- } catch (final HibernateException ex) {
- GenericDao.logger.error(ex);
- Session s = this.getSessionHibernate();
- s.getTransaction().rollback();
- s.clear();
- throw new HibernateException(ex);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement