首先是: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="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</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">password</property>
<mapping resource="com/ljg/domain/Employee.hbm.xml"/>
</session-factory>
</hibernate-configuration>
然后是 table.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">
<hibernate-mapping package="com.ljg.domain">
<class name="Employee" table="employee">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"/>
</id>
<property name="name" type="java.lang.String">
<column name="name" not-null="false"/>
</property>
<property name="email" type="java.lang.String">
<column name="email" not-null="false"/>
</property>
<property name="hireDate" type="java.util.Date">
<column name="hireDate" not-null="false"/>
</property>
</class>
</hibernate-mapping>