日期:2014-05-19 浏览次数:20691 次
<!-- 事务管理器配置, 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();
}