Spring Data JPA

Source: Internet
Author: User

1. How does Spring data JPA determine whether an object is a new object?

Spring data provides three strategies:

Able 2.2. Options for detection whether a 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 null The Id-property is and then the entity would be assumed as new, otherwise as not new.
ImplementingPersistable If an entity implements Persistable the interface, Spring Data JPA would delegate the New-detection isNew to the -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 have to register the custom implementation Ofjparepositoryfactory  as a Spring bean. Note that this should is rarely necessary. See The javadoc for details.

You can see that the default is to determine if there is an ID. You can then take other strategies, such as implementing an Persistable interface, and then overriding the IsNew method.

2. Spring Data annotations

Spring Data JPA

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.