gpt4 book ai didi

hibernate - 无法加载类 [oracle.jdbc.driver.Oracle 驱动程序]

转载 作者:行者123 更新时间:2023-12-02 22:44:49 27 4
gpt4 key购买 nike

我正在开发一个涉及 hibernate 的应用程序。当我调用我的应用程序时,我收到此异常:

org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [oracle.jdbc.driver.Oracle Driver] at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:245) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:200) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:156) at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:95) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94) at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845) at com.infy.EPP.resources.HibernateUtility.createSessionFactory(HibernateUtility.java:36) at com.infy.EPP.dao.BankLocationDAOImpl.getListOfBanks(BankLocationDAOImpl.java:27) at com.infy.EPP.business.service.BankLocationServiceImpl.getListOfBanks(BankLocationServiceImpl.java:20) at com.infy.EPP.web.managedbeans.BankLocationBean.(BankLocationBean.java:53) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at java.lang.Class.newInstance(Class.java:433) at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100) at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:71) at org.apache.el.parser.AstValue.getValue(AstValue.java:160) at org.apache.el.parser.AstEqual.getValue(AstEqual.java:37) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:106) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:457) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850) at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:431) at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:232) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at com.infy.EPP.web.filter.AuthenticationFilter.doFilter(AuthenticationFilter.java:57) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:744) Caused by: java.lang.ClassNotFoundException: Could not load requested class : oracle.jdbc.driver.Oracle Driver at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:230) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:340) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:242) ... 72 more

这是 hibernate.cfg.xml:

    <!-- hibernate dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.Oracle Driver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">oracle</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<!-- Automatic schema creation (begin) === -->
<property name="hibernate.hbm2ddl.auto">none</property>

<!-- Simple memory-only cache -->
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- <property name="show_sql">true</property> -->



<mapping class="com.infy.EPP.entites.LoginEntity" />


</session-factory>

这是 Hibernate 实用程序文件:

public class HibernateUtility 
{

private static final String CONFIGURATION_LOCATION = "com/infy/EPP/resources/hibernate.cfg.xml";
private static SessionFactory sessionFactory = null;
private static ServiceRegistry serviceRegistry;

public synchronized static SessionFactory createSessionFactory() {
if (sessionFactory == null)
{
try {
// Step1 : Loading the configuration details from
// hibernate.cfg.xml
Configuration configuration = new Configuration()
.configure(CONFIGURATION_LOCATION);
System.out.println("configuration in Utility=="+configuration); //---//syso1

// Step2 : Creating ServiceRegistry using the
// StandardServiceRegistryBuilder and Configuration defined in
// Step 1

serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();
System.out.println("serviceRegistry=="+serviceRegistry); ---//syso 2

// Step3 : Creating the SessionFactory using the Configuration
// and serviceRegistry.

sessionFactory = configuration
.buildSessionFactory(serviceRegistry);
System.out.println("sessionFactory==="+sessionFactory); ---//syso 3


}
catch (Exception e)
{
e.printStackTrace();
EppLogger.logError("HibernateUtility",
"createSessionFactory", e.getMessage());
}
}

return sessionFactory;
}

}

这是我调用它的 DAO 类方法:

public Login authorize(Login to) throws Exception 
{
LoginEntity le = null;
SessionFactory sessionFactory = null;
Session session = null;
Login login =null;
try {
sessionFactory = HibernateUtility.createSessionFactory();
session=sessionFactory.openSession();
session.beginTransaction();
le = (LoginEntity)session.get(LoginEntity.class, to.getUserId());
if (le != null)
{
login = new Login();
login.setPassword(le.getPassword());
login.setRole(le.getRole());
login.setStatus(le.getStatus());
login.setUserId(le.getUserId());
}
session.getTransaction().commit();
}
catch (PersistenceException exception) {
EppLogger.logError(this.getClass().getName(), "authorize",
exception.getMessage());
throw new Exception("DAO.TECHNICAL_ERROR");
}
catch (Exception e)
{
e.printStackTrace();
EppLogger.logError(this.getClass().getName(), "authorize", e.getMessage());
throw new Exception("DAO.TECHNICAL_ERROR");
}
finally
{
if(session!=null)
{
session.close();
sessionFactory.close();
}
}
return login;
}

我在lib文件夹下有ojdbc7。但它仍然不起作用。我浏览了 SO 上的几个页面,建议在类路径中添加 ojdbc14。还是没解决

更新:我已将一些 syso 语句放入 Hibernate Utility 文件中。我得到了前 2 个值,但没有得到第 3 个 syso 的值。

最佳答案

driver_class 属性中似乎有一个空格。

<property name="hibernate.connection.driver_class">oracle.jdbc.driver.Oracle    Driver</property>

甚至错误消息也表明了这一点。

尝试删除空格

也就是说,

<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

关于hibernate - 无法加载类 [oracle.jdbc.driver.Oracle 驱动程序],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31786014/

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