hibernate commit 问题 急!
我用的SQL2000,补丁是sp4。
程序目的是测试hibernate,但遇到了错误,请帮助!!!
test.java 是测试类。
package org.tong.hibernateDemo1;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.*;
import org.hibernate.cfg.Configuration;
public class test {
private static Log log = LogFactory.getLog(test.class);
public void find() {
SessionFactory sessionFactory;
try {
sessionFactory = new Configuration().configure()
.buildSessionFactory();
Session session = sessionFactory.openSession();
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void insert() {
SessionFactory sessionFactory;
try {
sessionFactory = new Configuration().configure()
.buildSessionFactory();
Person p = new Person();
p.setId("11111111");
p.setName("mmm");
p.setPassword("23");
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.save(p);
tx.commit();
session.close();
sessionFactory.close();
System.out.println("插入数据OK!请在MySQL查看结果!");
} catch (HibernateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) throws HibernateException {
new test().find();
new test().insert();
}
}
hibernate.cfg.xml 的内容是:
<?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">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=hibernate_test;SelectMethod=Cursor</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="myeclipse.connection.profile">person</property>
<property name="connection.password">sa</property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<mapping resource="org/tong/hibernateDemo1/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Person.hbm.xml 的内容是:
<?xml version="1.0" encoding='UTF-8'?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Thu Nov 09 16:06:12 CST 2006 -->
<hibernate-mapping package="org.tong.hibernateDemo1">
<class name="Person" table="PERSON">
<id name="id" column="ID" type="string">
<generator class="uuid.hex"/>
</id>
<property name="name" column="NAME" type="string" not-null="true" />
<property name="password" column="PASSWORD" type="string" not-null="true" />
<property name="sex" column="SEX" type="string" />
<property name="email" column="EMAIL" type="string" />
</class>
</hibernate-mapping>
错误提示是:
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/util/UtilUCS2InputStreamToCharacterReader
at com.microsoft.jdbc.base.BasePreparedStatement.setObjectInternal(Unknown Source)
at com.microsoft.jdbc.base.BasePreparedStatement.setString(Unknown Source)
at org.hibernate.type.StringType.set(StringType.java:24)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:39)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1617)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.tong.hibernateDemo1.test.insert(test.java:45)
at org.tong.hibernateDemo1.test.main(test.java:59)
test.java:45 是 tx.commit();
test.java:59 是 insert() 方法;
请帮助,如何改正错误!