标签: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注解
标签:http java os io strong for ar div cti
原文地址:http://www.cnblogs.com/ranger2016/p/3932469.html