首页 > 代码库 > Spring data jpa
Spring data jpa
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。