Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- src/main/java/centaurus/service/UserDao.java:7: error: package org.hibernate does not exist
- import org.hibernate.HibernateException;
- import centaurus.entity.GameUser;
- import restx.factory.Component;
- import org.hibernate.HibernateException;
- import org.hibernate.Session;
- import org.hibernate.Transaction;
- import org.hibernate.cfg.AnnotationConfiguration;
- import org.hibernate.SessionFactory;
- @Component
- public class UserDao {
- private static SessionFactory factory;
- public static void main(String[] args) {
- try{
- factory = new AnnotationConfiguration().
- configure().
- //addPackage("com.xyz") //add package if used.
- addAnnotatedClass(GameUser.class).
- buildSessionFactory();
- }catch (Throwable ex) {
- System.err.println("Failed to create sessionFactory object." + ex);
- throw new ExceptionInInitializerError(ex);
- }
- UserDao ME = new UserDao();
- }
- /* Method to CREATE an employee in the database */
- public Integer addEmployee(String email){
- Session session = factory.openSession();
- Transaction tx = null;
- Integer employeeID = null;
- try{
- tx = session.beginTransaction();
- GameUser employee = new GameUser();
- employee.setEmail(email);
- employeeID = (Integer) session.save(employee);
- tx.commit();
- }catch (HibernateException e) {
- if (tx!=null) tx.rollback();
- e.printStackTrace();
- }finally {
- session.close();
- }
- return employeeID;
- }
- public void saveId() {
- addEmployee("bob");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement