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才能运行?
如果高手看到,请指点一下,谢谢
- hibernate 的疑问
- 对Hibernate效率的疑问
- 关于hibernate级联修改的一些疑问
- 在使用webwork和Hibernate时的几点疑问
- Linux疑问---------文件系统的疑问---?????
- Hibernate中 session.delete()疑问?
- 关于Hibernate 重复获取主键和关联类的外键的疑问
- 公厕的疑问
- 我的疑问
- 自定义标签的疑问
- webservice的疑问
- strcpy的疑问
- for循环的疑问
- Spring的疑问若干
- C++的疑问
- 我的疑问?
- .NET发布的疑问?
- SelectionSet的疑问
- 长水痘
- 7.21随笔
- Java对象序列化(整理篇)
- 如何成为一个成功的Jsp程序员?
- delphi中的split函数
- hibernate 的疑问
- 非递归实现不重复序列的全排列(三)
- 技术成长历程(.net)9
- 我的处男作
- 终于有了自已的BLOG
- Tomcat + Apache安装实践 pomb [原作]
- ASP开发中关于RecordCount只返回-1的问题解接方式!
- 公钥密码系统及RSA公钥算法
- 史上最长的域名