原創|使用教程|編輯:龔雪|2018-03-06 10:35:40.000|閱讀 294 次
概述:本教程介紹了MyEclipse中的一些基于JPA / Spring的功能。有關設置JPA項目的基礎知識,請先閱讀JPA教程。 本教程主要關注MyEclipse中的JPA-Spring集成以及如何利用這些函數。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
MyEclipse 3.15 Style——在線購買低至75折!
【】
本教程介紹了MyEclipse中的一些基于JPA / Spring的功能。有關設置JPA項目的基礎知識,請先閱讀。 本教程主要關注MyEclipse中的JPA-Spring集成以及如何利用這些函數。您將學習到:
持續時間:30分鐘
沒有MyEclipse?
除了用戶管理事務外,Spring還通過@Transactional屬性支持容器管理事務。 對于容器管理的事務支持,當您添加facets時,必須啟用它,在前面的部分已經介紹過。
啟用它會將以下事務元素添加到您的bean配置文件中。 您還應該添加一個JPAServiceBean,它用于刪除使用容器管理的事務實體。 請參閱下面的實現:
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);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網