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