當前位置: 首頁>>代碼示例>>Java>>正文


Java HibernateException.printStackTrace方法代碼示例

本文整理匯總了Java中org.hibernate.HibernateException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java HibernateException.printStackTrace方法的具體用法?Java HibernateException.printStackTrace怎麽用?Java HibernateException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.hibernate.HibernateException的用法示例。


在下文中一共展示了HibernateException.printStackTrace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: p2w

import org.hibernate.HibernateException; //導入方法依賴的package包/類
public static void p2w(String username) {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	
	User newUser = new User("jeff", "myers", username, "jeff", "jeff");
	newUser.setApproved(true);
	newUser.setAvgScore(80.0);
	try {
		tx = session.beginTransaction();
		session.save(newUser);
		tx.commit();
		System.out.println("User: '" + newUser.getUsername() + "' has been successfully created!");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
		System.out.println("User creation failed!");
		he.printStackTrace();
		
	} finally {
		session.close();
	}
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:24,代碼來源:Driver2.java

示例2: getSessionFactory

import org.hibernate.HibernateException; //導入方法依賴的package包/類
public static SessionFactory getSessionFactory() {
        if (sessionFactory == null || sessionFactory.isClosed()) {
            try {
                Configuration configuration = new Configuration().configure();
                StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
                serviceRegistryBuilder.applySettings(configuration.getProperties());
                ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();
                sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//            sessionFactory = new Configuration().configure().buildSessionFactory();
            } catch (HibernateException ex) {
                ex.printStackTrace();
                System.err.println("Initial SessionFactory creation failed." + ex);
                throw new ExceptionInInitializerError(ex);
            }
        }
        return sessionFactory;
    }
 
開發者ID:drakonoved,項目名稱:userinterface,代碼行數:18,代碼來源:HibernateUtil.java

示例3: testUserCreation

import org.hibernate.HibernateException; //導入方法依賴的package包/類
public static void testUserCreation() {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	
	User newUser = new User("jef", "jeff", "jeff", "jeff", "jeff");
	//SQLIntegrityConstraintViolationException
	try {
		tx = session.beginTransaction();
		session.save(newUser);
		tx.commit();
		System.out.println("User: '" + newUser.getUsername() + "' has been successfully created!");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
		System.out.println("User creation failed!");
		he.printStackTrace();
		
	} finally {
		session.close();
	}
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:23,代碼來源:Driver2.java

示例4: getAllQuizzes

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public List<Quiz> getAllQuizzes(){
	Session session = HibernateUtil.getSession();
	Query query;
	String hql;
	Transaction tx = null;
	List<Quiz> quizzes = null;
	try {
		tx = session.beginTransaction();
		hql = "FROM io.flashboard.beans.quiz.Quiz";
		query = session.createQuery(hql);
		quizzes = query.list();

	} catch (HibernateException e) {
		if (tx != null) {
			tx.rollback();
		}
		e.printStackTrace();
	} finally {
		session.close();
	}
	return quizzes;		
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:24,代碼來源:QuizDaoImpl.java

示例5: addCommentByQuizId

import org.hibernate.HibernateException; //導入方法依賴的package包/類
public boolean addCommentByQuizId(int quizId, String username, String content) {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	Boolean success = false;
	Quiz quiz = new Quiz();
	Comment comment = new Comment(username, content);
	
	try {
		tx = session.beginTransaction();
		quiz = getQuizById(quizId);
		quiz.addComment(comment);
		session.save(quiz);
		System.out.println("Comment '" + comment.getCommentId() + "' successfully added to Quiz '" + quiz.getTestId() + "'.");
		success = true;
		tx.commit();
	} catch (HibernateException e) {
		if (tx != null) {
			tx.rollback();
		}
		success = false;
		e.printStackTrace();
	} finally {
		session.close();
	}
	return success;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:27,代碼來源:QuizDaoImpl.java

示例6: insertQuiz

import org.hibernate.HibernateException; //導入方法依賴的package包/類
public Integer insertQuiz(Quiz quiz) {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	Integer quizId = null;
	
	try {
		// Attemps to add and get quiz Id back
		tx = session.beginTransaction();
		quizId = (Integer) session.save(quiz);
		System.out.println(quizId);
		tx.commit();
	} catch (HibernateException e) {
		if (tx != null) {
			// Roll back IF transaction fails
			tx.rollback();
		}
		e.printStackTrace();
	} finally {
		session.close();
	}
	
	return quizId;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:24,代碼來源:QuizDaoImpl.java

示例7: getQuizById

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@Override
public Quiz getQuizById(int quizId) {
	Session session = HibernateUtil.getSession();
	Criteria criteria;
	Quiz test = null;
	
	try {
		criteria = session.createCriteria(Quiz.class);
		//Adds like restriction to search for a particular username
		test = (Quiz)criteria.add(Restrictions.like("quizId", quizId)).uniqueResult();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}finally {
		session.close();
	}
	return test;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:19,代碼來源:QuizDaoImpl.java

示例8: getQuizByTitle

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@Override
public Quiz getQuizByTitle(String quizTitle) {
	Session session = HibernateUtil.getSession();
	Criteria criteria;
	Quiz test = null;
	
	try {
		criteria = session.createCriteria(Quiz.class);
		//Adds like restriction to search for a particular username
		test = (Quiz)criteria.add(Restrictions.like("quizTitle", quizTitle)).uniqueResult();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}finally {
		session.close();
	}
	return test;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:19,代碼來源:QuizDaoImpl.java

示例9: getStudyGuide

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@Override
public StudyGuide getStudyGuide(int guideId) {
	
	Session session = HibernateUtil.getSession();
	Criteria criteria;
	StudyGuide studyGuide = null;
	try {
		criteria = session.createCriteria(StudyGuide.class);
		studyGuide = (StudyGuide) criteria.add(Restrictions.like("studyGuideId", guideId)).uniqueResult();

	} catch (HibernateException he) {
		he.printStackTrace();
	} finally {
		session.close();
	}
	return studyGuide;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:18,代碼來源:StudyGuideDaoImpl.java

示例10: getAllStudyGuides

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<StudyGuide> getAllStudyGuides() {
	Session session = HibernateUtil.getSession();
	Query query;
	String hql;
	Transaction tx = null;
	List<StudyGuide> guides = null;
	try {
		tx = session.beginTransaction();
		hql = "FROM io.flashboard.beans.studyguide.StudyGuide";
		query = session.createQuery(hql);
		guides = query.list();

	} catch (HibernateException e) {
		if (tx != null) {
			tx.rollback();
		}
		e.printStackTrace();
	} finally {
		session.close();
	}
	return guides;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:25,代碼來源:StudyGuideDaoImpl.java

示例11: createMessage

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@Override
public boolean createMessage(String username, String content) {
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	Boolean bool = false;
	Message message = new Message(username, content);
	
	try {
		tx = session.beginTransaction();
		session.save(message);
		tx.commit();
		bool = true;
		System.out.println("Message: '" + message.getMessageId() + "' has been successfully created!");
	} catch (HibernateException he) {
		if (tx != null) {
			tx.rollback();
		}
		System.out.println("Message creation failed!");
		he.printStackTrace();
		
	} finally {
		session.close();
	}
	return bool;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:26,代碼來源:MessageDaoImpl.java

示例12: getUserByUsername

import org.hibernate.HibernateException; //導入方法依賴的package包/類
/**
 * Gets a unique user from the database, if he/she exists
 * Utilizes Criterias
 * 
 * @param username username to be searched for
 * @return the user if he/she exists, otherwise null
 */
@Override
public User getUserByUsername(String username) {
	Session session = HibernateUtil.getSession();
	Criteria criteria;
	User user = null;
	
	try {
		criteria = session.createCriteria(User.class);
		//Adds like restriction to search for a particular username
		user = (User)criteria.add(Restrictions.like("username", username)).uniqueResult();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}finally {
		session.close();
	}
	return user;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:26,代碼來源:UserDaoImpl.java

示例13: getAllPromotees

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List<String> getAllPromotees(){
	Session session = HibernateUtil.getSession();
	List<String> promotees = new ArrayList<>();
	
	Criteria criteria;
	
	try {
		criteria = session.createCriteria(User.class);
		promotees = criteria.add(Restrictions.ge("avgScore", 70.0))
				.add(Restrictions.like("approved", true))
				.setProjection(Projections.property("username")).list();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}finally {
		session.close();
	}
	
	if(promotees.isEmpty()) {
		promotees = null; 
	}
	
	return promotees;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:27,代碼來源:UserDaoImpl.java

示例14: getQuizComments

import org.hibernate.HibernateException; //導入方法依賴的package包/類
@Override
public List<Comment> getQuizComments(int quizId) {
	List<Comment> comments = new ArrayList<>();
	Session session = HibernateUtil.getSession();
	Criteria criteria = null;
	Quiz q = null;
	
	Query query = null;
	StudyGuide sg = null;
	String hql = "FROM StudyGuide WHERE studyGuideId = :id";
	
	try {
		criteria = session.createCriteria(Quiz.class);
		q = (Quiz)criteria.add(Restrictions.like("quizId", quizId)).uniqueResult();
		
		comments = q.getComments();
	}
	catch(HibernateException he) {
		he.printStackTrace();
	}
	
	if(comments.isEmpty()) {
		return null;
	}
	
	return comments;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:28,代碼來源:QuizDaoImpl.java

示例15: addQuizComment

import org.hibernate.HibernateException; //導入方法依賴的package包/類
/**
 * Adds comments to a quiz
 * quiz is found by id and comments are inserted
 * 
 * @param comment contents
 * @param quiz id
 * 
 * @return true if comment add, otherwise false
 * 
 */
@Override
public boolean addQuizComment(Comment comment, int quizId) {
	Quiz q = getQuizById(quizId);
	
	if(q == null) {
		return false;
	}
	
	Session session = HibernateUtil.getSession();
	Transaction tx = null;
	q.getComments().add(comment);
	
	try {
		tx = session.beginTransaction();
		
		session.update(q);
		
		tx.commit();
		
		return true;
	}
	catch(HibernateException he) {
		if(tx != null) {
			tx.rollback();
		}
		he.printStackTrace();
	}
	finally {
		session.close();
	}
	
	
	return false;
}
 
開發者ID:grantleymorrison,項目名稱:FlashBoard,代碼行數:45,代碼來源:QuizDaoImpl.java


注:本文中的org.hibernate.HibernateException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。