hibernate 无法访问javax.persistence.criterial.CriteriaDelete类文件,找不到javax.persistence.criterial.CriteriaDelete类文件

llycmphe  于 2023-03-30  发布在  Java
关注(0)|答案(1)|浏览(161)

我正在学习Hibernate。我想连接SQL服务器。我写了这段代码,我收到一个异常

SessionFactory factory = new Configuration()
        .configure("hibernate.cfg.xml")
        .addAnnotatedClass(Car.class)
        .buildSessionFactory();

Session session = factory.getCurrentSession();

try {
    session.beginTransaction();
    List<Car> cars =  session.createQuery("from cars").getResultList();

    for (Car car : cars) {
        System.out.println(car.getCars_name());
    }

    session.getTransaction().commit();
} finally {
    factory.close();
}

无法访问javax.persistence.criterial.CriteriaDelete类文件,找不到javax.persistence.criterial.CriteriaDelete类文件

yv5phkfx

yv5phkfx1#

我以为依赖是缺失的:

<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>javax.persistence-api</artifactId>
            <version>2.2</version>
        </dependency>

相关问题