hibernate2.0连数据库问题,之前一直用的MYSQL完全正常,这次用MSSQL2000请高手指点

Cupid1945 2006-05-21 12:09:33
我的hibernate.properties文件是这样写的
## MS SQL Server

hibernate.dialect net.sf.hibernate.dialect.SQLServerDialect
hibernate.connection.username sa
hibernate.connection.password sa

## Microsoft Driver
hibernate.connection.driver_class com.microsoft.jdbc.sqlserver.SQLServerDriver
hibernate.connection.url jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=UFDATA_777_2006;SelectMethod=cursor


hibernate.cfg.xml中

<property name="connection.datasource">java:comp/env/Red</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=UFDATA_777_2006</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">sa</property>

<mapping resource="com/jiangkui/jkoms/hibernate/Operator.hbm.xml"/>

然后我写了个创建表的类

public class MyServlet // extends HttpServlet
{

public static void main(String[] args)
{
try
{
Configuration conf =
new Configuration()

.addClass(Operator.class);


SessionFactory sessions = conf.buildSessionFactory();

SchemaExport dbExport = new SchemaExport(conf);
dbExport.setOutputFile("D:\\sql4.txt");
dbExport.create(true, true);

Session s = sessions.openSession();
Transaction t = s.beginTransaction();

t.commit();
s.close();
}
catch (Exception e)
{
System.out.println(e);
}

}
}

运行MyServlet.java
报错如下

Exception in thread "main" java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:45)
at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:37)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:235)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:750)
at com.jiangkui.jkoms.hibernate.MyServlet.main(MyServlet.java:43)

然后我更换数据库驱动为

## jTDS
hibernate.connection.driver_class net.sourceforge.jtds.jdbc.Driver
hibernate.connection.url jdbc:jtds:sqlserver://localhost:1433;DatabaseName=UFDATA_777_2006;SelectMethod=cursor
hibernate.jdbc.use_scrollable_resultset false

hibernate.cfg.xml中
<property name="connection.datasource">java:comp/env/RedstoneSql</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:jtds:sqlserver://localhost:1433;DatabaseName=UFDATA_777_2006</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">sa</property>

<mapping resource="com/jiangkui/jkoms/hibernate/Operator.hbm.xml"/>

报错依然为
Exception in thread "main" java.lang.IllegalAccessError
at net.sf.cglib.core.ClassEmitter.setTarget(ClassEmitter.java:45)
at net.sf.cglib.core.ClassEmitter.<init>(ClassEmitter.java:37)
at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:165)
at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:117)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.hibernate.impl.SessionFactoryImpl.<clinit>(SessionFactoryImpl.java:235)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:750)
at com.jiangkui.jkoms.hibernate.MyServlet.main(MyServlet.java:43)

我引的包是 cglbi-2.1_3.jar 官方的
查了两天不明白这个错怎么回事,请高手一定指点啊,因为任务很紧急啊.
...全文
103 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Cupid1945 2006-06-27
原来是hibernate包不对
回复
Cupid1945 2006-05-21
ding
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-05-21 12:09
社区公告
暂无公告