2016-02-12 32 views
0
log4j:WARN No appenders could be found for logger (org.jboss.logging). 
log4j:WARN Please initialize the log4j system properly. 
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to 
create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.createServ 
ice(AbstractServiceRegistryImpl.java:244) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize 
Service(AbstractServiceRegistryImpl.java:208) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService 
(AbstractServiceRegistryImpl.java:189) 
     at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcSer 
vicesImpl.java:51) 
     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.conf 
igureService(StandardServiceRegistryImpl.java:94) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize 
Service(AbstractServiceRegistryImpl.java:217) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService 
(AbstractServiceRegistryImpl.java:189) 
     at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTy 
pes(MetadataBuildingProcess.java:352) 
     at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete 
(MetadataBuildingProcess.java:111) 
     at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(Me 
tadataBuildingProcess.java:83) 
     at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilder 
Impl.java:418) 
     at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilder 
Impl.java:87) 
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav 
a:692) 
     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.jav 
a:724) 
     at Test.main(Test.java:14) 
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: U 
nable to load class [com.mysql.jdbc.Driver] 
     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceI 
mpl.classForName(ClassLoaderServiceImpl.java:229) 
     at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectio 
nProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:161) 

     at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectio 
nProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:117) 
     at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectio 
nProviderImpl.configure(DriverManagerConnectionProviderImpl.java:73) 
     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.conf 
igureService(StandardServiceRegistryImpl.java:94) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.initialize 
Service(AbstractServiceRegistryImpl.java:217) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService 
(AbstractServiceRegistryImpl.java:189) 
     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.build 
JdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) 
     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initi 
ateService(JdbcEnvironmentInitiator.java:66) 
     at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initi 
ateService(JdbcEnvironmentInitiator.java:35) 
     at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.init 
iateService(StandardServiceRegistryImpl.java:88) 
     at org.hibernate.service.internal.AbstractServiceRegistryImpl.createServ 
ice(AbstractServiceRegistryImpl.java:234) 
     ... 14 more 
Caused by: java.lang.ClassNotFoundException: Could not load requested class : co 
m.mysql.jdbc.Driver 
     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceI 
mpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:217) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     at java.lang.ClassLoader.loadClass(Unknown Source) 
     at java.lang.Class.forName0(Native Method) 
     at java.lang.Class.forName(Unknown Source) 
     at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceI 
mpl.classForName(ClassLoaderServiceImpl.java:226) 
     ... 25 more 

我想在Hibernate中構建我的簡單應用程序。爲什麼我在Hibernate中出錯?

我正在使用mysql數據庫。

我已經編譯了所有類......並使用命令提示符運行Test(包含main方法)類。

<?xml version='1.0' encoding='UTF-8'?> 
<!DOCTYPE hibernate-configuration PUBLIC 
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 

<hibernate-configuration> 

    <session-factory> 
     <property name="hbm2ddl.auto">update</property> 
     <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="connection.url">jdbc:mysql://localhost/hibernate</property> 
     <property name="connection.username">root</property> 
     <property name="connection.password"></property> 
     <property name="dialect"> 
      org.hibernate.dialect.MySQLDialect 
     </property> 

     <!-- Echo all executed SQL to stdout --> 
     <property name="show_sql">true</property> 

    <mapping resource="student.hbm.xml"/> 
    </session-factory> 

</hibernate-configuration> 

這與hibernate配置錯誤有關嗎?

回答

2

你得到一個ClassNotFoundException

com.mysql.jdbc.Driver,你需要MySQL驅動jar添加到您的構建路徑。

+0

好的謝謝它完成了:-) –

1

您必須在您的項目中添加mysql驅動程序jar。 如果您正在使用Maven,只需添加依賴於你的POM文件:

<dependency> 
    <groupId>mysql</groupId> 
    <artifactId>mysql-connector-java</artifactId> 
    <version>5.1.38</version> 
</dependency> 

如果沒有,請下載並安裝從mysql.com網站的罐子。

相關問題