gpt4 book ai didi

java - hibernate 配置: Jar files?

转载 作者:太空宇宙 更新时间:2023-11-04 11:58:23 24 4
gpt4 key购买 nike

我是菜鸟,但我一直在这里找到问题的解决方案,但我没有看到它......我是 hibernate 新手,我利用空闲时间来学习这一点。

package negocio;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry;


import integracion.HibernateUtil;
import integracion.dao.BodegaDAOImpl;
import integracion.dao.VinoDAO;
import integracion.dao.VinoDAOImpl;
import integracion.entidades.Bodega;

public class Main {

public static void main(String[] args) {

SessionFactory sessionFactory;


Configuration configuration = new Configuration();
configuration.configure();

ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
//The problem is here
**sessionFactory = configuration.buildSessionFactory(serviceRegistry);**

Session session = sessionFactory.openSession();
BodegaDAOImpl bodegaDao = new BodegaDAOImpl<>();
bodegaDao.get(1);


}

}

这是添加的 jar 列表 1

这是映射文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/vinoteca</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="hibernate.show_sql">true</property>


<mapping class="integracion.entidades.Vino"/>
<mapping class="integracion.entidades.Bodega"/>
<mapping class="integracion.entidades.Denominacion"/>

</session-factory>
</hibernate-configuration>




dic 15, 2016 12:37:51 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.9.Final}
dic 15, 2016 12:37:51 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
dic 15, 2016 12:37:51 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
dic 15, 2016 12:37:51 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
dic 15, 2016 12:37:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
dic 15, 2016 12:37:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/vinoteca]
dic 15, 2016 12:37:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=root, password=****}
dic 15, 2016 12:37:51 AM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
dic 15, 2016 12:37:51 AM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Thu Dec 15 00:37:51 CET 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
dic 15, 2016 12:37:51 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
at org.hibernate.cfg.AnnotationBinder.bindDefaults(AnnotationBinder.java:259)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.prepare(AnnotationMetadataSourceProcessorImpl.java:184)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.prepare(MetadataBuildingProcess.java:156)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:253)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:692)
at negocio.Main.main(Main.java:31)
Caused by: java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 9 more

所以..这就是问题所在。当 eclipse 说 java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery

时,我看到了这个问题

是因为没有添加jar(javax.persistence.jar或hibernate-jpa-2.1-api-1.0.0...jar),但我添加了它们,但我没有解决这个问题。

有人会问我为什么工作不好?谢谢!PD:对不起我的英语,我不是英语母语=)

最佳答案

使用 maven 或 gradle 等构建系统来构建项目,并添加对 hibernate 的依赖。这几乎肯定会解决所有与依赖相关的基本类路径问题。

关于java - hibernate 配置: Jar files?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41154321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com