MyEclipse 3.15 Style——在线购买低至75折!火爆开抢>>数据库
【MyEclipse最新版下载】eclipse
本教程介绍了MyEclipse中的一些基于JPA / Spring的功能。有关设置JPA项目的基础知识,请先阅读JPA教程。 本教程主要关注MyEclipse中的JPA-Spring集成以及如何利用这些函数。您将学习到:函数
持续时间:30分钟学习
没有MyEclipse? 如今下载ui
除了用户管理事务外,Spring还经过@Transactional属性支持容器管理事务。 对于容器管理的事务支持,当您添加facets时,必须启用它,在前面的部分已经介绍过。this
启用对@Transactional注释的支持spa
启用它会将如下事务元素添加到您的bean配置文件中。 您还应该添加一个JPAServiceBean,它用于删除使用容器管理的事务实体。 请参阅下面的实现:设计
注释驱动的配置元素blog
JPAServiceBean实现以下所示;请注意deleteProductLine方法上的@Transactional注释以及缺乏任何用户管理的事务语句。教程
public class JPAServiceBean { private IProductlineDAO dao; @Transactional public void deleteProductLine(String productlineID) { /* 1. Now retrieve the new product line, using the ID we created */Productline loadedProductline = dao.findById(productlineID); /* 2. Now let's delete the product line from the DB */ dao.delete(loadedProductline); /* * 3. To confirm the deletion, try and load it again and make sure it * fails */ Productline deletedProductline = dao.findById(productlineID); /* * 4. We use a simple inline IF clause to test for null and print * SUCCESSFUL/FAILED */ System.out.println("Productline deletion: " + (deletedProductline == null ? "SUCCESSFUL" : "FAILED"));} public void setProductLineDAO(IProductlineDAO dao) { this.dao = dao; } }
从应用程序上下文中获取JPAServiceBean的一个实例并按以下所示使用它:
JPAServiceBean bean = (JPAServiceBean) ctx.getBean("JPAServiceBean"); bean.deleteProductLine(productlineID);