当前位置: 首页>>代码示例>>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;未经允许,请勿转载。