码迷,mamicode.com
首页 > 编程语言 > 详细

Spring data jpa

时间:2014-08-24 09:09:02      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:http   java   os   io   strong   for   ar   div   cti   

1. Spring data jpa怎么去判断一个对象的是否为新对象呢?

 spring  data 提供了三种策略:

able 2.2. Options for detection whether an entity is new in Spring Data JPA

Id-Property inspection (default) By default Spring Data JPA inspects the Id-Property of the given Entity. If the Id-Property is null, then the entity will be assumed as new, otherwise as not new.
ImplementingPersistable If an entity implements the Persistable interface, Spring Data JPA will delegate the new-detection to the isNew - Method of the Entity. See theJavaDoc for details.
ImplementingEntityInformation One can customize the EntityInformation abstraction used in the SimpleJpaRepository implementation by creating a subclass ofJpaRepositoryFactory and overriding the getEntityInformation-Method accordingly. One then has to register the custom implementation ofJpaRepositoryFactory as a Spring bean. Note that this should be rarely necessary. See the JavaDoc for details.

 可以看出默认是判断是否有id。然后也可以采取其他策略,比如实现Persistable接口,然后重写isNew方法。

 

2. Spring data注解

 

Spring data jpa

标签:http   java   os   io   strong   for   ar   div   cti   

原文地址:http://www.cnblogs.com/ranger2016/p/3932469.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!