您的位置:首页 > 其它

ssh之雇员管理系统(2)-hibernate测试

2013-05-13 17:04 483 查看
二、测试hibernate是否配置成功

View Code

package com.wang.ssh;

import org.apache.bsf.util.event.adapters.java_awt_event_ActionAdapter;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.wang.domain.Employee;
import com.wang.service.imp.EmployeeService;
import com.wang.service.interfaces.EmployeeServiceInter;

public class Test {
public static void main(String[] args) {
/**
* 测试Spring配置是否成功
*/
//        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
//        TestServcie testServcie = (TestServcie)ac.getBean("testServcie");
//        System.out.println(testServcie.getName()+"***");

/**
* 测试hibernater是否配置成功
*/
ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory= (SessionFactory) ac.getBean("sessionFactory");
Session session =  sessionFactory.openSession();
Employee employee = new Employee("Tom", "123@qq.com", new java.util.Date(), 123.45f);
Transaction transaction = session.beginTransaction();
session.save(employee);
transaction.commit();
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: