Advertisement
Guest User

Untitled

a guest
May 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. src/main/java/centaurus/service/UserDao.java:7: error: package org.hibernate does not exist
  2. import org.hibernate.HibernateException;
  3.  
  4. import centaurus.entity.GameUser;
  5.  
  6. import restx.factory.Component;
  7.  
  8. import org.hibernate.HibernateException;
  9. import org.hibernate.Session;
  10. import org.hibernate.Transaction;
  11. import org.hibernate.cfg.AnnotationConfiguration;
  12. import org.hibernate.SessionFactory;
  13.  
  14. @Component
  15. public class UserDao {
  16. private static SessionFactory factory;
  17.  
  18. public static void main(String[] args) {
  19. try{
  20. factory = new AnnotationConfiguration().
  21. configure().
  22. //addPackage("com.xyz") //add package if used.
  23. addAnnotatedClass(GameUser.class).
  24. buildSessionFactory();
  25. }catch (Throwable ex) {
  26. System.err.println("Failed to create sessionFactory object." + ex);
  27. throw new ExceptionInInitializerError(ex);
  28. }
  29. UserDao ME = new UserDao();
  30. }
  31.  
  32. /* Method to CREATE an employee in the database */
  33. public Integer addEmployee(String email){
  34. Session session = factory.openSession();
  35. Transaction tx = null;
  36. Integer employeeID = null;
  37. try{
  38. tx = session.beginTransaction();
  39. GameUser employee = new GameUser();
  40. employee.setEmail(email);
  41. employeeID = (Integer) session.save(employee);
  42. tx.commit();
  43. }catch (HibernateException e) {
  44. if (tx!=null) tx.rollback();
  45. e.printStackTrace();
  46. }finally {
  47. session.close();
  48. }
  49. return employeeID;
  50. }
  51.  
  52. public void saveId() {
  53. addEmployee("bob");
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement