hibernate commit 问题 急!

tjm624 2007-05-12 09:14:50
我用的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() 方法;
请帮助,如何改正错误!

...全文
262 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnsida 2008-09-09
  • 打赏
  • 举报
回复
uuid.hex 这个是随机32位的,看是不是数据库里的长度不够,我猜的
aChinese 2007-05-14
  • 打赏
  • 举报
回复
com/microsoft/util/UtilUCS2InputStreamToCharacterReader
这个类找不到, 检查一下是不是少放了什么包

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧