Hibernate同一个session中刷新对象和数据库里同步
摘要://场景:使用了延迟加载, //所以使用了org.springframework.orm.hibernate3.support.OpenSessionInViewFilter //现在又一个request得到后台A有一个children属性,现在给A对象的children中添加一个child,调用的是action中的save方法(save中保存child). //当添加完成以后,在action中resultType为chain,跳转到list方法,list方法又查询了A对象的信息。这个时候如果不this.getSession().refresh(obj); //...
阅读全文
posted @
2013-03-12 10:50
cfd406635982
阅读(3164)
推荐(0) 编辑
Hibernate 语句执行顺序控制
摘要:public class XXDAOHibernateImpl extends HibernateDaoSupport implements IXXDAO<Discount>{ @Override public void allOper(Disc disc) { this.deleteXXInfos(); //...A this.getSessionFactory().getCurrentSession().flush(); this.update(disc); //...B this.getSessionFactory()....
阅读全文
posted @
2012-12-26 11:22
cfd406635982
阅读(1376)
推荐(0) 编辑
用spring的InitializingBean的afterPropertiesSet来初始化
摘要:org.springframework.beans.factory包下有一个接口是InitializingBean 只有一个方法:/** * Invoked by a BeanFactory after it has set all bean properties supplied * (and satisfied BeanFactoryAware and ApplicationContextAware). * <p>This method allows the bean instance to perform initialization only * possible when
阅读全文
posted @
2012-12-21 12:01
cfd406635982
阅读(27564)
推荐(0) 编辑
SpringAop 事务传播行为
摘要:在配置spring事务传播行为的时候,如果在一个类里有多个方法class A{public addA(){//something...}public addB(){//something...}public addAll(){addA();addB();}}如:addB 和 addAll的传播行为为REQUIRE如果addA的传播行为为REQUIRES_NEW当调用addAll的时候并不会给addA()重新开启一个事务,而是在addAll事务之中因为spring的AOP和动态代理的的原因:在一次方法调用过程中一个类中的方法只会被代理一次,不会被多次代理,而且代理的是调用的那个方法。所以如果调用
阅读全文
posted @
2012-12-19 11:03
cfd406635982
阅读(497)
推荐(0) 编辑
Junit测试 解决Lazy加载时 Session关闭的问题。
摘要:继承以下类即可:import org.hibernate.FlushMode;import org.hibernate.Session;import org.hibernate.SessionFactory;import org.junit.After;import org.junit.Before;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.orm.hibernate3.SessionFactor
阅读全文
posted @
2012-12-18 15:15
cfd406635982
阅读(2515)
推荐(0) 编辑