这段时间准备把几个基础库类重写,之前发现了Spring升级到3.1之后以前写的DAO类出现deprecated的问题,当时没有仔细研究把Spring降到3.0.5了事。最近突然想到这个问题觉得还是要研究一下,于是找来资料看看,发现Spring在3.1之后决定完全支持JPA2标准,准备放弃之前的JpaDaoSupport和JpaTemplate等。也就是说,以后Spring不再使用JpaTemplate的方式去回调实现JPA的接口,而是完全采用注解和注入的方式去实现,这样就实现了Spring的完全解耦合。恩,是个不错的思路!
对比一下代码来发现不同之处
3.1之前我扩展的DAO类
public abstract class StrongDAOImpl<E, PK extends Serializable> extends JpaDaoSupport implements StrongDAO<E, PK> {
public Class<E> entityClass;
@SuppressWarnings("unchecked")
public StrongDAOImpl() {
this.entityClass = (Class<E>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
@Override
public void delete(final E entity) {
getJpaTemplate().remove(entity);
}
@Override
public void delete(final PK id) {
E entity = this.getByID(id);
if (entity != null) {
delete(entity);
}
}
3.1之后的实现方法
public abstract class StrongDAOImpl<E, PK extends Serializable> implements StrongDAO<E, PK> {
@PersistenceContext
private EntityManager entityManager;
public EntityManager getEntityManager() {
return this.entityManager;
}
public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}
public void delete(E entity) {
if (entity == null) {
return;// //////
} else {
entityManager.remove(entity);
}
}
public void delete(PK id) {
if (id != null) {
E entity = this.getByID(id);
this.delete(entity);
} else {
return;// //////
}
}
要吃早餐了,先写到这里。如果有时间把扩展DAO类全部移植到Spring3.1+我再来更新
分享到:
相关推荐
12.6.2. JpaTemplate 和 JpaDaoSupport 12.6.3. 基于原生的JPA实现DAO 12.6.4. 异常转化 12.6.5. 事务管理 12.6.6. JpaDialect III. Web 13. Web框架 13.1. 介绍 13.1.1. 与其他web框架的集成 13.1.2. Spring Web ...
deprecated-2.0.1.gem 下载
Dear Spring community, I’m pleased to announce that Spring Framework 5.0.2 and 4.3.13 are available now, as a pair of refinement releases which are recommended as immediate upgrades for all Spring ...
添加一个console.warn声明至函数利用@deprecated tag注释
前端开源库-deprecated已弃用,用于弃用事物的工具
php解决Deprecated Automatically populating is deprecated and will be removed
/home/data/anaconda3/lib/python3.7/site-packages/pymysql/cursors.py:170: Warning: (1681, 'Integer display width is deprecated and will be removed in a future release.') result = self._query(query) ...
xorg-x11-deprecated-libs-6.8.2-37.FC4.49.2.1.x86_64.rpm
安装pip install Deprecated用法要使用此功能,请使用@deprecated装饰器装饰不推荐使用的函数: from deprecated import deprecated@ deprecateddef some_old_function ( x , y ): return x + y 您还可以修饰一个类...
[DEPRECATED] 硬币电子化回收箱 2016年中美青年创客大赛天津赛区作品解决方案 [DEPRECATED] 硬币电子化回收箱 2016年中美青年创客大赛天津赛区作品解决方案 [DEPRECATED] 硬币电子化回收箱 2016年中美青年创客大赛...
xorg-x11-deprecated-libs-6.8.2.rpm for redhat
deprecated-list.html
离线安装包,亲测可用
用 @Deprecated注解的程序元素,不鼓励程序员使用这样的元素,通常是因为它很危险或存在更好的选择,本文给大家介绍java @deprecated注解的作用及传递性,对本文感兴趣的朋友一起学习吧
C#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 A0071_DeprecatedC#例子代码 ...
3.1. Improved Getting Started Experience .................................................................. 17 3.2. Removed Deprecated Packages and Methods ...............................................
2020假期spring学习 1.注解和反射 1.注解 Java 注解(Annotation)又称 Java 标注,是 JDK5.0 引入的一种注释机制。 Java 语言中的类、方法、变量、参数和包等都可以被标注。 内置的注解 作用在代码的注解是 @...
Hessian与spring整合的dome
yum 下载xorg-x11-deprecated-libs-6.8.2-31.i386.rpm 有问题,使用该报的rpm文件
主要介绍了PHP提示Deprecated: mysql_connect(): The mysql extension is deprecated的解决方法,是在进行PHP数据库程序开发中常会遇到的错误,需要的朋友可以参考下