日期:2014-05-19  浏览次数:20622 次

spring开启事物失败
hql语句能正常显示结果, 自己配置事物也能正常插入数据, 但是 spring 托管事物以后失败(数据插不进去,没提交...),我怀疑是配置文件没弄好..  附下 本人配置事物方式..帮忙看下 哪里错误
 

<!-- 事务管理器配置, Jpa单数据源事务 -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="transactionManager"/>

插入的方法,没有程序没异常报出,但是 没数据插入

@Transactional
public Serializable save(T o) {
this.getCurrentSession().persist(o);
return null;
}

假如 我如下写法 是正确的,

@Test  
    public void testSessionFactory(){  
        System.out.println(ctx.getBean("dataSource"));  
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();  
        Employee model = new Employee();
        model.setPassword("123456");
        model.setPhone("15029332");
        model.setUsername("ewwqeqweqwe");
        model.setName("d09dsa");
        entityManager.persist(model);
        entityManager.getTransaction().commit();
        
    } 

 帮忙解答下, 就先贴这些,如果各位还要求我贴出哪个地方的代码,说下... 在线等
spring?hibernate?事物

------解决方案--------------------
怎没没有看见事务配置在哪个层上面?
------解决方案--------------------
帮顶接分