Ejemplo n.º 1
0
  public void deleteNews(News news) {
    Session session = null;
    Transaction tr = null;

    try {
      session = SessionFactory.getSession();
      tr = session.beginTransaction();
      session.delete(news);
      tr.commit();
    } catch (Exception e) {
      tr.rollback();
    } finally {
      session.close();
    }
  }
Ejemplo n.º 2
0
 public List<News> getNews3() {
   Session session = null;
   Transaction tr = null;
   try {
     session = SessionFactory.getSession();
     String queryString = "from News where type = 3 order by times desc";
     tr = session.beginTransaction();
     List<News> news = session.createQuery(queryString).list();
     tr.commit();
     return news;
   } catch (Exception e) {
     tr.rollback();
     return null;
   } finally {
     session.close();
   }
 }
Ejemplo n.º 3
0
 public News getNewsById(Integer id) {
   Session session = null;
   Transaction tr = null;
   try {
     session = SessionFactory.getSession();
     String queryString = "from News where id=" + id;
     tr = session.beginTransaction();
     List<News> news = session.createQuery(queryString).list();
     tr.commit();
     return news.get(0);
   } catch (Exception e) {
     tr.rollback();
     return null;
   } finally {
     session.close();
   }
 }