发信人: yimi (一米阳光), 信区: Java
标 题: spring中annotation问题
发信站: 日月光华 (2008年06月18日11:38:07 星期三), 站内信件
spring中的@Transactional需要什么配置么?
执行update以后,发现transaction没提交过,数据库没有变化
//===============================================================
Service类:
@Transactional(readOnly = false)
public void update(T t) {
dao.update(t);
logger.debug("run in update");
}
DAO类:
//getSession()方法返回一个hibernate session对象
public void update(T t){
getSession().update(t);
}
public class PersonTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext factory=new
FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
IService ps = (IService)factory.getBean("personService");
System.out.println(ps.getClass());
Person person = (Person)ps.findById(1L);
person.setFirstName("aa");
ps.update(person);
}
}
写了一个Test类:
public class PersonTest {
/**
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext factory=new
FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
IService ps = (IService)factory.getBean("personService");
System.out.println(ps.getClass());
Person person = (Person)ps.findById(1L);
person.setFirstName("aa");
ps.update(person);
}
}
原来是BaseDao没有继承HibernateDaoSupport。。
session管理和transaction机制
http://www.iteye.com/topic/35907?page=1