package com.webFrame.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.webFrame.bean.User;
public class SpringTest {
private static ApplicationContext ac;
@BeforeClass
public static void testAc() {
ac = new ClassPathXmlApplicationContext(new String[] {
"classpath:spring.xml", "classpath:spring-hibernate.xml" });
}
// 测试sessionFactory
@Test
public void testSessionFactory() {
SessionFactory sessionFactory = (SessionFactory) ac
.getBean("sessionFactory");
System.out.println(sessionFactory);
}
// 测试事务
@Test
public void testTransaction() {
SessionFactory sessionFactory = (SessionFactory) ac
.getBean("sessionFactory");
// 获取或打开session
Session session = sessionFactory.openSession();
// 开启事务处理
Transaction ts = session.beginTransaction();
User u = new User();
u.setId(null);
u.setName("小明");
session.save(u);
ts.commit();
session.cancelQuery();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
webFrame.zip (39个子文件)
webFrame
.project 2KB
.mymetadata 305B
src
test
resources
java
com
webFrame
test
SpringTest.java 1KB
TestAction.java 270B
bean
User.java 312B
User.hbm.xml 403B
main
webapp
WEB-INF
classes
lib
web.xml 3KB
index.jsp 829B
META-INF
MANIFEST.MF 39B
test.jsp 316B
resources
spring-hibernate.xml 7KB
struts.xml 2KB
config.properties 1KB
log4j.properties 572B
spring.xml 727B
java
target
m2e-jee
web-resources
META-INF
MANIFEST.MF 114B
maven
webFrame
webFrame
pom.properties 220B
pom.xml 6KB
classes
spring-hibernate.xml 7KB
struts.xml 2KB
config.properties 1KB
log4j.properties 572B
spring.xml 727B
test-classes
com
webFrame
test
SpringTest.class 2KB
TestAction.class 638B
bean
User.class 761B
User.hbm.xml 403B
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.m2e.core.prefs 121B
org.eclipse.jdt.core.prefs 461B
org.eclipse.wst.jsdt.ui.superType.name 6B
com.genuitec.eclipse.j2eedt.core.prefs 87B
org.eclipse.core.resources.prefs 104B
org.eclipse.wst.common.component 750B
.jsdtscope 508B
.classpath.bak 690B
pom.xml 6KB
.classpath 719B
共 39 条
- 1
_Jorden_
- 粉丝: 19
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页