Java Dependency问题,不适用于hibernate

时间:2016-05-28 12:21:19

标签: java hibernate maven

您好我正在尝试按照本教程:: http://www.tutorialspoint.com/hibernate/hibernate_annotations.htm

我的代码如果你想挖掘就在这里: https://github.com/ArthurGibbs/Centaurus-

我正在使用restx框架。

我正在尝试使用hibernate来访问本地数据库。但是,当我尝试编译我的代码时,我得到一个依赖性错误:

src/main/java/centaurus/service/UserDao.java:7: error: package org.hibernate does not exist
import org.hibernate.HibernateException;

但是我把它包含在我的pom中所以我不明白为什么我会收到错误。

这是我的班级,其中有错误指向     包centaurus.service;

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");
    }
}

hibernate新手,对maven不太熟悉。请帮忙或让我知道如何帮助你。提前谢谢

1 个答案:

答案 0 :(得分:0)

因为我正在使用restx,它不会读取pom,它会读取md.restx.json文件,其中我缺少依赖项依赖项