新手,hibernate配置问题
本帖最后由 luoning1217 于 2012-11-13 14:50:29 编辑
想用hibernate连sqlserver2005 express
用的最新版hibernate 4.1.8
主配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration >
<session-factory>
<property name = "hibernate.connection.url ">jdbc:sqlserver://localhost:1841;DatabaseName=Hibernate</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 ">sa</property>
<property name = "hibernate.dialect ">org.hibernate.dialect.SQLServer2005Dialect</property>
<property name = "show_sql ">true</property>
<mapping resource="Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
简单测试程序想保存一条记录:
package com.test.ognl;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.test.util.HibernateUtil;
public class HibernateTest1 {
public static void main(String[] args)
{
Session session = HibernateUtil.OpenSession();
Transaction tx = session.beginTransaction();
Customer customer = new Customer();
customer.setName("zhangsan");
try
{
session.save(customer);
tx.commit();
}
catch(Exception ex)
{
if(null != tx)
{
tx.rollback();
}
}
finally
{
session.close();
}
}
}
运行后报如下错误:
2012/11/13 14:45:56 org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2012/11/13 14:45:56 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.8.Final}
2012/11/13 14:45:56 org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
2012/11/13 14:45:56 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
2012/11/13 14:45:56 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
2012/11/13 14:45:56 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
2012/11/13 14:45:57 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: Customer.hbm.xml
2012/11/13 14:45:57 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
2012/11/13 14:45:57 org.hibernate.cf