我下载H3 把hibernate3.jar和lib下的所有文件都放在了Tomcat的一个应用web-inf/lib下然后在classes目录下创建了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"><hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">
jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=MySql
</property>
<property name="hibernate.connection.driver_class">
com.microsoft.jdbc.sqlserver.SQLServerDriver
</property>
<property name="hibernate.connection.username">
sa
</property>
<property name="hibernate.connection.password">
123
</property>
<property name="dialect">  
  org.hibernate.dialect.SybaseDialect  
</property>
<property name="show_sql">
True
</property>
<property name="hibernate.use_outer_join">
True
</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<mapping resource="org/mytest/hibernate/Mytable.hbm.xml"/>
</session-factory>
</hibernate-configuration>然后写了一段测试程序,如下package test.hibernate.servlet;import javax.servlet.*;
import javax.servlet.http.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
import org.mytest.hibernate.*;
import java.io.*;public class TestOne  extends HttpServlet{

private static final long serialVersionUID = 1;

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
response.setContentType("text/html;charset=gb2312");
try{
Configuration config = new Configuration().configure();
config.addClass(Mytable.class);
SessionFactory sessionFactory = config.buildSessionFactory();
sessionFactory.close();
response.sendRedirect("index.jsp");

catch (HibernateException e) {   
response.sendRedirect("error.jsp");
}
catch(Exception e){
response.sendRedirect("error2.jsp");
}
finally{
}
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
doPost(request,response);
}}发现每次都抛出了HibernateException错误为什么我创建不了SessionFactory啊 ,请教教我

解决方案 »

  1.   

    org.hibernate.dialect.SybaseDialect  跟 com.microsoft.jdbc.sqlserver.SQLServerDriver 对不上吧。
      

  2.   

    楼上说的对,你的org.hibernate.dialect.SybaseDialect 跟你的数据库 驱动不对应是吧,
      

  3.   

    呵呵,,,,
    Hibernate的方言和数据库不匹配,怎么能正确呢?????
      

  4.   

    那我应该用什么呢?
    我查阅了Hibernate3.jar下的包
    没有发现MSSQL名称的是否是用SQLServerDialet
      

  5.   

    查看hibernate/etc下的hibernate.properties这个文件,找到对应的数据方言你要记得给分啊
      

  6.   

    还是不行。。
    我改成了SQLServletDialet还是照样抛出HibernateException....到底为什么
      

  7.   

    终于成功了 错误的地方在于 我用middlengn生成的hbm.xml文件 格式头为2。0的修改成3。0以后 顺利通过。耗费了我几个小时。 不过对配置hibernate有了更清晰的了解了晚上结帖 多谢楼上几位。