请教一下,我在整合两个框架的时候,做单元测试的时候,数据都能顺利的插入到数据库,但是用hibernate统计信息的时候,出现如下信息:
Statistics[start time=1311748544875,sessions opened=1,sessions closed=1,transactions=2,successful transactions=1,optimistic lock failures=0,flushes=1,connections obtained=1,statements prepared=4,statements closed=4,second level cache puts=0,second level cache hits=0,second level cache misses=0,entities loaded=0,entities updated=0,entities inserted=4,entities deleted=0,entities fetched=0,collections loaded=0,collections updated=0,collections removed=0,collections recreated=0,collections fetched=0,queries executed to database=0,query cache puts=0,query cache hits=0,query cache misses=0,max query time=0]
transactions=2,successful transactions=1
这里我弄不明白是什么原因。怎么事务的打开有两次,却只成功了一次。我在网上搜索了一下,没有很好的解答,但是在http://www.iteye.com/problems/60481上,这个人的问题和我一样。请大家帮助解答一下。谢谢
我把我的代码发上来请高手帮我看看:
类ServiceImpl :
@Component("service")
@Transactional
public class ServiceImpl implements Service {
@Resource(name="personDAO")
private PersonDAO personDAO;
public void service1() {
personDAO.save(new Person("yangjun"));
personDAO.save(new Person("alex"));
}
}
类PersonDAOImpl :
@Component("personDAO")
@Transactional
public class PersonDAOImpl implements PersonDAO {
@Resource(name = "sessionFactory")
private SessionFactory sessionFactory;
public void save(Person person) {
sessionFactory.getCurrentSession().persist(person);
}
}
单元测试:
@Test
public void testService1(){
try {
service.service1();
} catch (Exception e) {
System.out.println("----------"+e.getMessage());
}
Statistics st=sessionFactory.getStatistics();
System.out.println("----------------hibernate统计信息:"+st);
System.out.println("打开事务次数:"+st.getTransactionCount());
System.out.println("成功事务次数:"+st.getSuccessfulTransactionCount());
}
}