今天尝试了下Hibernate连接SQL Server2005,将源码放松如下: 同时注意有几点,貌似不能通过"hibernate.hbm2ddl.auto=update"属性在SQL中建立数据库,必须将数据库先手动生成,但是可以自动生成表。
另外注意下载SQL 2005的JDBC驱动,我用的是Myeclipse 8,自带hibernate 3.3
所以不用下载Hibernate了。

Hibernate配置文件
xml version ='1.0' encoding ='UTF-8' ?>
                    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
                    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


< hibernate-configuration >

< session-factory >
   < property name ="hibernate.hbm2ddl.auto" >update property >
   < property name ="dialect" >
    org.hibernate.dialect.SQLServerDialect
   property >
   < property name ="connection.url" >
    jdbc:sqlserver://localhost:1433;databaseName=Test
   property >
   < property name ="connection.username" >sa property >
   < property name ="connection.password" >sa property >
   < property name ="connection.driver_class" >
    com.microsoft.sqlserver.jdbc.SQLServerDriver
   property >


   < property name ="show_sql" >true property >
   < mapping resource ="com/visionsky/domain/User.hbm.xml" />

session-factory >

hibernate-configuration >

定义的User类

package com.visionsky.domain;

import java.util.Date;

public class User {
  
   private int id;
   private String name;
   private    Date birthday;
   public int getId() {
     return id;
  }
   public void setId( int id) {
     this.id = id;
  }
   public String getName() {
     return name;
  }
   public void setName(String name) {
     this.name = name;
  }
   public Date getBirthday() {
     return birthday;
  }
   public void setBirthday(Date    date) {
     this.birthday = date;
  }
  

}

User类的配置文件
xml version ="1.0" ?>
                                                                     "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

< hibernate-mapping package ="com.visionsky.domain" >
< class name ="User" table ="`User`" >
     < id name ="id" >
     < generator class ="native" />
     id >
     < property generated ="never" lazy ="false" name ="name" type ="string" />
     < property generated ="never" lazy ="false" name ="birthday" type ="date" />
class >
hibernate-mapping >

程序主体:
package com.visionsky;

import java.util.Date;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.visionsky.domain.User;

public class Base {

   /**
    * @param args
    */

   public static void main(String[] args) {
     // TODO Auto-generated method stub
    Configuration cfg= new Configuration();
    cfg.configure();
    SessionFactory sf=cfg.buildSessionFactory();
    
    Session s=sf.openSession();
    Transaction tx=s.beginTransaction();
    User user= new User();
    user.setBirthday( new Date());
    
    user.setName( "vision");
    s.save(user);
    tx.commit();
    
    s.close();
    System.out.println( "end");
  }

}