org.hibernate.HibernateException.printStackTrace()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(125)

本文整理了Java中org.hibernate.HibernateException.printStackTrace()方法的一些代码示例,展示了HibernateException.printStackTrace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HibernateException.printStackTrace()方法的具体详情如下:
包路径:org.hibernate.HibernateException
类名称:HibernateException
方法名:printStackTrace

HibernateException.printStackTrace介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private static SessionFactory seesionFactory = null;
 private static final SessionFactory makeSessionFactory()
 {
   try {
          if (sessionFactory==null)
     seesionFactory = new Configuration().configure().buildSessionFactory();
   } catch (HibernateException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
  return seesionFactory;    
 }

代码示例来源:origin: stackoverflow.com

Session session=null;
  try {
   session =HibernateUtil.getSessionFactory().openSession();
 } catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
 }finally
 {
   session.close();
 }

代码示例来源:origin: stackoverflow.com

Session session=null;
 Transaction tx=null;
  try {
   session =HibernateUtil.getSessionFactory().openSession();
   tx=session.beginTransaction();
   } catch (HibernateException e) {
 e.printStackTrace();
 }finally
 {
   session.close();
 }

代码示例来源:origin: stackoverflow.com

} catch (HibernateException e) {
  if (tx != null) {
    try {
      tx.rollback();
    } catch(Exception re) {
      System.err.println("Error when trying to rollback transaction:"); // use logging framework here
      re.printStackTrace();
    }
  }
  System.err.println("Original error when executing query:"); // // use logging framework here

  e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

public Integer search(HashMap<String, Object> params) {
  Session sesion = sessionFactory.openSession();
  Integer id = null;
  try{
    List lista = sesion.createCriteria(User.class).add(
        Restrictions.eq("name",(String)params.get("name"))).list();
    if(lista.size() == 1){id = ((User)lista.get(0)).getId();}
  }catch(HibernateException he){
    he.printStackTrace();
  }finally{sesion.close();}
  return id;
}

代码示例来源:origin: stackoverflow.com

public List<Car> findAll() {
  List<Car> carsList = new ArrayList<Car>();
  try {
    query = session.createQuery("from Car");
    carsList = query.list();
    for (Iterator iterator = carsList.iterator(); iterator.hasNext(); ) {
      Car car = (Car) iterator.next();
    }
  } catch (HibernateException he) {
    he.printStackTrace();
  } finally {

  }
  return carsList;
}

代码示例来源:origin: stackoverflow.com

Session session = HibernateUtil.getSession();
try {
  String hql = "FROM TreeNode tn JOIN tn.nodeAsset WHERE tn.id=5";
  Query query = session.createQuery(hql);
  List result = query.list();
  System.out.println("done");
} catch (HibernateException e) {
  e.printStackTrace();
  throw new Exception("Query failed", e);
} finally {
  session.flush();
  session.close();
}

代码示例来源:origin: stackoverflow.com

public String getCustomerEmail(){
   Session session = HibernateSessionFactory.getSession();
   //Session session = sessionFactory.openSession();
   String maxOrderNoDay = "";
   try{
     maxOrderNoDay = (String) session.createQuery("select cus.mail from Customer cus join cus.mainOrder man WHERE man.id = 1").uniqueResult();
     //
     System.out.println(maxOrderNoDay);
   }catch(HibernateException e){
     e.printStackTrace();
   }finally{
     session.close();
     return  maxOrderNoDay;
   }
 }

代码示例来源:origin: stackoverflow.com

try {
  System.out.println("Begin transaction");
  session.beginTransaction();

  System.out.println("Save mortgage");
  session.save(mortgage);
  System.out.println("Commit transaction");
  session.getTransaction().commit();

  System.out.println("Close session");
  session.close();
  System.out.println("Close SessionFactory");
  HibernateUtil.getSessionFactory().close();
} catch (HibernateException he) {
  he.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

private Session getSession(SessionFactory sessionFactory){
 Session session = null;
 try{
   session = sessionFactory.getCurrentSession();
 }catch(HibernateException hex){
   hex.printStackTrace();
 }
 if(session == null && !session.isClosed()){
   session = sessionFactory.openSession();
 }
}

代码示例来源:origin: mifos/head

public void shutdown() {
  try {
    sessionFactory.close();
    sessionTL.remove();
    interceptorTL.remove();
  } catch (HibernateException e) {
    e.printStackTrace(System.out);
  }
  sessionFactory = null;
}

代码示例来源:origin: stackoverflow.com

public static void setConnectionProperties() {
  URL configFileURL = null;

  try {
    configFileURL = URL_OF_YOUR_CFG_XML_FILE;
    configuration = (new Configuration()).configure(configFileURL);
    sessionFactory = configuration.buildSessionFactory();

  } catch (HibernateException e) {
    e.printStackTrace(); 
    System.out.println("Error while initializing hibernate: " + e.getMessage());
  }

}

代码示例来源:origin: stackoverflow.com

String[] splitQueryStr = queryString.split(";");
 for (String queryStr : splitQueryStr) {
   try {
     getSession().beginTransaction();
     getSession().createSQLQuery(queryStr).executeUpdate();
     getSession().getTransaction().commit();
   } catch (HibernateException he) {
     getSession().getTransaction().rollback();
     he.printStackTrace();
     throw new HibernateException("Hibernate Error");
   } catch (Exception e) {
     getSession().getTransaction().rollback();
     throw new Exception();
   } 
 }

代码示例来源:origin: stackoverflow.com

public void deleteEmployee (Integer EmployeeID){
 Session session = factory.openSession();
 Transaction tx = null;
  try {
    tx = session.beginTransaction();
    Employee employee =
          (Employee) session.get(Employee.class, EmployeeID);
    session.delete(employee);
    tx.commit();
  } catch (HibernateException e) {
    if (tx != null) tx.rollback();
    e.printStackTrace();
  } finally {
    session.close();
  }
}

代码示例来源:origin: stackoverflow.com

public void addGrade(Grade grade) {
 Session session = sessionFactory.getCurrentSession()
  Transaction tx = null;
  try{
  tx = session.beginTransaction();
  session.save(grade);   
  tx.commit();
   }catch (HibernateException e) {
    if (tx!=null) tx.rollback();
    e.printStackTrace(); 
  }finally {
    session.close(); 
  }
  }

代码示例来源:origin: stackoverflow.com

public TestType getTestTypeById(int idTestType) {
  Session session = sf.openSession(); // sf as a sessionFactory instance
  Transaction tx = null;
  TestType testType = null;
  try {
    tx = session.beginTransaction();
    testType = (TestType) session.get(TestType.class, idTestType);
    tx.commit();
  } catch (HibernateException e) {
    if (tx != null)
      tx.rollback();
    e.printStackTrace();
  } finally {
    session.close();
  }

  return testType;
}

代码示例来源:origin: stackoverflow.com

Session s = HibernateUtil.getSessionFactory().openSession();
 Transaction tx = null;
 try {
   tx = s.beginTransaction();        
   // here get object
   List<Employee> list = s.createCriteria(Employee.class).list();
   tx.commit();
 } catch (HibernateException ex) {
   if (tx != null) {
     tx.rollback();
   }            
   Logger.getLogger("con").info("Exception: " + ex.getMessage());
   ex.printStackTrace(System.err);
 } finally {
   s.close(); 
 }

代码示例来源:origin: stackoverflow.com

public void save(Object entity) {

  Session session = HibernateUtil.getSessionFactory().openSession();
  Transaction transaction = null;
  try {
    transaction = session.beginTransaction();
    session.save(entity);                     
    transaction.commit();
  } catch (HibernateException e) {
    System.out.println("Exception:"+e.getMessage());
    transaction.rollback();
    e.printStackTrace();
  } finally {
    session.close();
  }
}

代码示例来源:origin: stackoverflow.com

public User updateUser(User user) {

  try {
    User result = session.get(User.class, user.getId());
    if (result == null) {
      throw new FilamentNoSuchRecordException(new CoreError(304, "User does not exist"));
    }
    result.setName(user.getName()); // update some properties
    session.update(result); // you should update 'result', not 'user'

    return result;
  } catch (HibernateException e) {
    e.printStackTrace();
    throw new FilamentDataConnectivityException(new CoreError(305,"Connectivity issue. Please see System Administrator"));
  }

}

代码示例来源:origin: stackoverflow.com

public void addRolesToUser(Role roles,UserDao user) {
  try{ 
   session.beginTransaction();
    roles=new Role();
    user=new UserDao();
    user.getRoles().add(roles);
    session.save(roles);
    session.save(user);
    session.getTransaction().commit();
  }catch(HibernateException e){
    session.getTransaction().rollback();
    e.printStackTrace();
  }
 }

相关文章