简体   繁体   中英

Does spring-data-neo4j have a beforeSave method?

How can I execute some code just before an entity is saved?

@NodeEntity
public class Person {

    @Transient
    String password
    String passwordHash

    public void beforeSave() { // I made this method name up.
        if (password != null && !password.isEmpty()) {
            passwordHash = AuthenticationService.encodePassword(email, password);
            password = null;
        }
    }
}

Do I need to use AspectJ or is there a simpler way using an annotation?

I've added the following dependencies:

compile("org.springframework.data:spring-data-neo4j:3.3.0.RELEASE")
compile("org.springframework.data:spring-data-neo4j-rest:3.3.0.RELEASE")

In SDN3, you have BeforeSave ApplicationEvents like in the rest of the Spring Data projects.

http://docs.spring.io/spring-data/data-neo4j/docs/3.3.0.RELEASE/reference/html/#lifecycle_events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM