spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
3.03k stars 1.43k forks source link

Ref doc - explain about save strategy repositories [DATAJPA-344] #753

Closed spring-projects-issues closed 11 years ago

spring-projects-issues commented 11 years ago

Michael Isvy opened DATAJPA-344 and commented

I understand that by default, generated save methods do something like that:

if (owner.getId() == null) {
        this.em.persist(owner);             
}
else {
      this.em.merge(owner);    
}

It would be nice to mention it in the ref doc, especially because we can't debug those classes to find out how they work (because proxies are generated at startup time). Here is an email that Oliver sent me on this topic, guessing that it will save some time for the ref doc:

See [0]. By default this can be customized implementing Persistable with your domain class which exposes an ....isNew() method. If you need more advanced usecases, you can implement the EntityInformation abstraction used in the repo implementation by customizing the repository factory [1], but that should be rerely needed.

Cheers, Ollie

[0] https://github.com/SpringSource/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java#L352 [1] https://github.com/SpringSource/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactory.java#L144


No further details from DATAJPA-344

spring-projects-issues commented 11 years ago

Thomas Darimont commented

Added requested additional sections in pull request: https://github.com/SpringSource/spring-data-jpa/pull/32