示例#1
0
 @Override
 public List<Information> getsendinfobyid(int uid) {
   List<Information> result = new ArrayList<Information>();
   Session session = sessionFactory.openSession();
   String sql = "select * from Information where senderid= '" + uid + "'";
   try {
     session.beginTransaction();
     Query query = session.createSQLQuery(sql);
     List<Object[]> object = query.list();
     for (Object[] o : object) {
       Information temp = new Information();
       User r = new User();
       User s = new User();
       r.setUid((int) o[2]);
       s.setUid((int) o[3]);
       temp.setInfoid((int) o[0]);
       temp.setContext((String) o[1]);
       temp.setSendtime((Timestamp) o[4]);
       temp.setState((int) o[5]);
       temp.setSender(s);
       temp.setReceiver(r);
       result.add(temp);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     session.getTransaction().commit();
     session.close();
     return result;
   }
 }
示例#2
0
 @Override
 public int addinfo(String context, User sender, User receiver) {
   int result = 1;
   Information info = new Information();
   info.setState(1);
   info.setContext(context);
   info.setReceiver(receiver);
   info.setSender(sender);
   Session session = sessionFactory.openSession();
   try {
     session.beginTransaction();
     session.save(info);
     System.out.println("__________________????");
   } catch (Exception e) {
     result = 0;
     e.printStackTrace();
   } finally {
     session.getTransaction().commit();
     session.close();
     System.out.println("_________________result");
     return result;
   }
 }