hibernate连的oracle数据库测试junit报错,请问是哪里错了?
import java.util.Date; public class Students { private int sid; private String sname; private String gender; private Date birthday; private String address; public Students(){ } public Students(int sid, String sname, String gender, Date birthday, String address) { //super(); this.sid = sid; this.sname = sname; this.gender = gender; this.birthday = birthday; this.address = address; } public int getSid() { return sid; } public void setSid(int sid) { this.sid = sid; } public String getSname() { return sname; } public void setSname(String sname) { this.sname = sname; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } @Override public String toString() { // TODO Auto-generated method stub return "Students [sid=" + sid +",sname="+ sname + ", gender=" + gender+",birthday = "+ birthday + ",address =" + address +"]"; } }
hibernate.cfg.xml如下:
<?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="connection.username">dbusrmkt</property> <property name="connection.password">futuremkt</property> <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property> <property name="connection.url">jdbc:oracle\:thin\:@172.17.11.60\:1521\:HDQTLS</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="show_sql">true</property> <property name="format_sql">true</property> <property name="hbm2ddl.auto">create</property> <property name="hibernate.default_schema">dbusrmkt</property> <mapping resource="Students.hbm.xml"/> </session-factory> </hibernate-configuration>
StudentsTest 测试类如下:
import java.util.Date; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; import org.junit.After; import org.junit.Before; import org.junit.Test; public class StudentsTest { private SessionFactory sessionFactory; private Session session; private Transaction transaction; @Before public void init() { //创建配置对象 Configuration config = new Configuration().configure(); //创建服务注册对象 ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry(); //创建会话工厂对象 sessionFactory = config.buildSessionFactory(serviceRegistry); //会话对象 session = sessionFactory.openSession(); //开启事务 transaction = session.beginTransaction(); } @After public void destory() { transaction.commit();//提交事务 session.close();//关闭会话 sessionFactory.close();//关闭会话工厂 } @Test public void testSaveStudents() { Students s = new Students(1,"张三","男",new Date(),"武汉"); session.save(s); } }
求教啊,谢谢!