首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate4.1.8 有关问题 雪中坐等

2012-12-16 
hibernate4.1.8 问题 雪中坐等public class Test {public static void main(String[] args) {Student sne

hibernate4.1.8 问题 雪中坐等


public class Test {

public static void main(String[] args) {

Student s=new Student();
s.setId(1);
s.setName("penglei");
s.setAge(25);

Configuration config=new Configuration().configure();
ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();         
    SessionFactory sf=config.buildSessionFactory(sr); 
Session session=sf.openSession();
session.beginTransaction();
session.save(s);
session.getTransaction().commit();
session.close();
sf.close();

}

}

2012-11-20 18:38:49 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2012-11-20 18:38:49 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
2012-11-20 18:38:49 org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5}
2012-11-20 18:38:49 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2012-11-20 18:38:49 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2012-11-20 18:38:49 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
2012-11-20 18:38:49 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/zzk/hibernate/model/Student.hbm.xml
2012-11-20 18:38:49 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
2012-11-20 18:38:49 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Exception in thread "main" org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver oracle.jdbc.driver.OracleDriver class not found
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:107)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)


at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:77)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
at Test.main(Test.java:22)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [oracle.jdbc.driver.OracleDriver]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:104)
... 13 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : oracle.jdbc.driver.OracleDriver
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
... 14 more



[最优解释]
  Could not load requested class  : oracle.jdbc.driver.OracleDriver 


  
你确定你引入了oracle驱动 的jar包?  貌似是classes14.jar吧  我也忘了、oracle 10的jar包还真不知道、

如果你确定你引入了oracle驱动的jar、那么就是他运行的时候找不到该jar的路径

[其他解释]

public class FirstHibernate {     public static void main(String[] args) {                   //1.使用configuration初始化hibernate读取配置文件         Configuration config=new Configuration();         config.configure();//默认加载hibernate.cfg.xml的配置文件         //config.configure("hibernate.cfg.xml");//配置文件自定义配置         //2构建sessionfactory         SessionFactory fac=config.buildSessionFactory();                   //3生成session         Session session=fac.openSession();//使用默认session         //4.开始事务         Student s=new Student();         s.setId(1);         s.setName("briup");         s.setAddress("briup");         s.setAge(12);          Transaction tr=session.beginTransaction();         session.save(s);//提交操作s         //save delete update                   tr.commit();         session.close();               } }


[其他解释]
运行
SessionFactory sf=config.buildSessionFactory(sr); 
出的错
[其他解释]
 Configuration config=new Configuration().configure();      \
这句话好像错了
 Configuration config=new Configuration();
 config.configure();//默认加载hibernate.cfg.xml的配置文件 
你仔细想想这两者的区别 。
[其他解释]
一样还是这个错误!!!

[其他解释]
什么意思。。。。

[其他解释]

//1.使用configuration初始化hibernate读取配置文件 
 Configuration config=new Configuration(); 
config.configure();//默认加载hibernate.cfg.xml的配置文件 
 //config.configure("hibernate.cfg.xml");//配置文件自定义配置 
//2构建sessionfactory 
SessionFactory fac=config.buildSessionFactory(); 
 //3生成session 
 Session session=fac.openSession();//使用默认session 
  //4.开始事务 
Student s=new Student(); 
s.setId(1);         
s.setName("briup");         
s.setAddress("briup");         
s.setAge(12);          
Transaction tr=session.beginTransaction(); 
session.save(s);//提交操作s         
//save delete update                   
tr.commit();         
session.close(); 

如果还有问题的话,就是你hibernate.cfg.xml有问题了
[其他解释]
4.1.8 不让用buildSessionFactory() 方法了

[其他解释]

<?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>

        <!-- Database connection settings -->
        <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
        <property name="connection.url">jdbc:oracle:thin:@192.168.1.100:1521:miracle</property>
        <property name="connection.username">scott</property>
        <property name="connection.password">fuckme</property>

        <!-- JDBC connection pool (use the built-in) -->
        <!--  <property name="connection.pool_size">1</property> -->

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property>



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

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

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

        <!-- Drop and re-create the database schema on startup -->
        <!--  <property name="hbm2ddl.auto">update</property>-->

        <mapping resource="com/zzk/hibernate/model/Student.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


[其他解释]
File file = new File("F:\\workspace\\hibernate\\src\\hibernate.cfg.xml");    

2 Configuration config = new Configuration().configure(file);           

3 ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(    

4                         config.getProperties()).buildServiceRegistry();    

5 sessionFactory = config.buildSessionFactory(sr); 

路径改成绝对的,再试试,如果还不行,那我就真没办法了。
[其他解释]
一样 。。。。不过还是谢谢

[其他解释]
崩溃了 弄了1天。。。。
[其他解释]
引用:
Could not load requested class  : oracle.jdbc.driver.OracleDriver 


  
你确定你引入了oracle驱动 的jar包?  貌似是classes14.jar吧  我也忘了、oracle 10的jar包还真不知道、

如果你确定你引入了oracle驱动的jar、那么就是他运行的时候找不到该jar的路径

+1
[其他解释]
没引oracle jar包。。。。
我都快哭了 谢谢各位
[其他解释]
引用:
没引oracle jar包。。。。
我都快哭了 谢谢各位




以后出错了要记得 看错误信息、别怕英文不英文、
Caused by 引起错误原因、
实在不行就翻译、最后就知道大概是什么错了、

热点排行