Author: azeez
Date: Tue Feb 12 07:19:44 2008
New Revision: 13655

Log:

Fixing hibernate related bugs



Modified:
   
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadHibernateConfig.java
   
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadPersistenceManager.java

Modified: 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadHibernateConfig.java
==============================================================================
--- 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadHibernateConfig.java
   (original)
+++ 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadHibernateConfig.java
   Tue Feb 12 07:19:44 2008
@@ -22,11 +22,10 @@
 import org.hibernate.cfg.Configuration;
 
 /**
- * Initializes & manages the Hibernate configuration 
+ * Initializes & manages the Hibernate configuration
  */
 public class ChadHibernateConfig {
     public final SessionFactory SESSION_FACTORY;
-    public final ThreadLocal SESSION = new ThreadLocal();
 
     /**
      * Default Constructor. This should be package protected since we should 
only instantiate it
@@ -47,22 +46,8 @@
             throw new ExceptionInInitializerError(ex);
         }
     }
-    
-    public Session currentSession() throws HibernateException {
-        Session session = (Session) SESSION.get();
-        if (session == null) {
-            session = SESSION_FACTORY.openSession();
-            SESSION.set(session);
-        }
-        return session;
-    }
 
-    public void closeSession() throws HibernateException {
-        Session session = (Session) SESSION.get();
-        if (session != null) {
-            session.close();
-        }
-        SESSION.set(null);
+    public Session currentSession() throws HibernateException {
+        return SESSION_FACTORY.getCurrentSession();
     }
 }
-

Modified: 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadPersistenceManager.java
==============================================================================
--- 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadPersistenceManager.java
        (original)
+++ 
branches/wsas/java/2.2/wsas/java/modules/samples/Chad/src/org/wso2/wsas/sample/chad/data/ChadPersistenceManager.java
        Tue Feb 12 07:19:44 2008
@@ -59,7 +59,6 @@
         adminUser.setLastUpdatedTime(new Date());
         try {
             session.persist(adminUser);
-            session.flush();
             tx.commit();
         } catch (ConstraintViolationException e) {
             String msg = "Administrator " + username.trim() + " already 
exists";
@@ -68,8 +67,6 @@
         } catch (Exception e) {
             tx.rollback();
             throw new RuntimeException("Cannot create Administrator account", 
e);
-        } finally {
-            hbConfig.closeSession();
         }
     }
 
@@ -92,8 +89,6 @@
             tx.commit();
         } catch (Throwable t) {
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
     }
 
@@ -116,10 +111,9 @@
             log.warn(msg, e);
             throw new DuplicatePollException(msg, e);
         } catch (Exception e) {
+            e.printStackTrace();
             tx.rollback();
             throw new RuntimeException("Cannot create entity", e);
-        } finally {
-            hbConfig.closeSession();
         }
     }
 
@@ -139,10 +133,9 @@
             admin = (AdminUser) criteria.uniqueResult();
             session.evict(admin);
             tx.commit();
-        } catch (Throwable t) {
+        } catch (Throwable e) {
+            e.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
         return admin;
     }
@@ -173,9 +166,8 @@
         } catch (ChadAuthenticationException e) {
             throw e;
         } catch (Throwable t) {
+            t.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
     }
 
@@ -196,9 +188,8 @@
             session.evict(poll);
             tx.commit();
         } catch (Throwable t) {
+            t.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
         return poll;
     }
@@ -221,9 +212,8 @@
                 users[i++] = ((AdminUser) iterator.next()).getUsername();
             }
         } catch (Throwable e) {
+            e.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
         return users;
     }
@@ -243,9 +233,8 @@
             polls = (ChadPoll[]) list.toArray(new ChadPoll[list.size()]);
             tx.commit();
         } catch (Throwable t) {
+            t.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
         return polls;
     }
@@ -262,9 +251,8 @@
             session.update(poll);
             tx.commit();
         } catch (Throwable t) {
+            t.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
     }
 
@@ -327,9 +315,8 @@
             }
             tx.commit();
         } catch (Throwable t) {
+            t.printStackTrace();
             tx.rollback();
-        } finally {
-            hbConfig.closeSession();
         }
         return result;
     }

_______________________________________________
Wsas-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to