Example #1
0
 public Forum getForumById(int forumId) {
   // TODO Auto-generated method stub
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   Forum forum = new Forum();
   try {
     tx = session.beginTransaction();
     forum = (Forum) session.get(Forum.class, forumId);
     // System.out.println("First Name - "+user.getFirstname());
     // System.out.println("Last Name - "+user.getLastname());
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return forum;
 }
Example #2
0
 @Override
 public User getUser(int userId) {
   // TODO Auto-generated method stub
   System.out.println("DbHelper->getUser...");
   Session session = sessionFactory.openSession();
   Transaction tx = null;
   User user = new User();
   try {
     tx = session.beginTransaction();
     user = (User) session.get(User.class, userId);
     // System.out.println("First Name - "+user.getFirstname());
     // System.out.println("Last Name - "+user.getLastname());
   } catch (HibernateException e) {
     if (tx != null) {
       tx.rollback();
       e.printStackTrace();
     }
   } finally {
     session.close();
   }
   return user;
 }