hibernate 的疑问

来源:互联网 发布:开淘宝店需要的软件 编辑:程序博客网 时间:2024/04/30 05:09

刚开始学习hibernate,第一个程序在tomcat下通过servlet可以运行,但我想在普通的程序下,比如main()函数中通过hibernate来持久华,老是出现下列错误

log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoClassDefFoundError: java/sql/Savepoint
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:218)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at net.sf.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:95)
        at net.sf.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71)
        at net.sf.hibernate.cfg.Configuration.buildSettings(Configuration.java:1078)
        at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
        at test.main(test.java:12)

this is the hibernate.cfg.xml
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd";>

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
<property name="hibernate.connection.username">ODBC</property>
<property name="hibernate.connection.password"> </property>
<property name="show_sql">true</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="./com/hibernate/courses.hbm.xml"/>

</session-factory>

</hibernate-configuration>

this is the test.java测试用的
import java.io.*;
import net.sf.hibernate.cfg.*;
import net.sf.hibernate.*;
import com.hibernate.*;
import java.sql.*;
public class test{
 public static void main(String [] argv){
  SessionFactory sf;
  Session s;
  Transaction tx;
  try{System.out.println("before");
   sf=new Configuration().configure().buildSessionFactory();
   System.out.println("success");
   s=sf.openSession();
   tx=s.beginTransaction();
   //tranaction
   Courses course=new Courses();
   course.setId("sfsunk");
   course.setName("sunfei");
   s.save(course);
   tx.commit();
   s.close();
   
  }catch(Exception e){
   e.printStackTrace();
  }
  
  
 }
 
 
}

=============
这是.bat文件
set lib=../lib
set mycp=%CLASSPATH%;%lib%/cglib2.jar;%lib%/commons-collections.jar;%lib%/commons-logging.jar;%lib%/dom4j.jar;%lib%/hibernate2.jar;%lib%/log4j.jar;%lib%/odmg.jar;%lib%/xml-apis.jar;%lib%/xerces-2.4.0.jar;%lib%/mysql-connector-java-3.1.1-alpha-bin.jar;%lib%/jdbc2_0-stdext.jar;%lib%/jta.jar
java  -classpath %mycp% test

搞了一天都没搞定,对我打击太大了,直到现在。

难道hibernate也需要在依赖于容器比如tomcat才能运行?

如果高手看到,请指点一下,谢谢

 

原创粉丝点击