similar actions to @PrePersist @PreUpdate in spring-data-es without using JPA?












1















I would like to update my entities upon persistence, with their creationDate/updateDate and createdBy/updatedBy.



Using JPA I would use @PrePersist and @PreUpdate and will update via a method for each.



I'm not using spring-data-jpa but using spring-data-elasticsearch.



I have normal Document entities with inheritence relationships. I want my BaseDocument to save automatically it creationDate/update and createdBy/update fields.



Iv'e found this solution- how to Spring-data MongoDB @prepersist @preupdate without using JPA
using Spring-data-commons annotation, using @CreatedBy , @CreatedDate, @LastModifiedBy, @LastModifiedDate. I don't see how this would fit here, as I want any logic to be set only when persistence is taken. this seems to work with auditing.



Another option I could do is using Spring AOP with @Before annotation, but I'm not sure how to enforce it to be done before/after persistence.



Thanks!










share|improve this question

























  • Just use the @CreatedBy etc, that has nothing to do with auditing at all.

    – M. Deinum
    Nov 14 '18 at 14:08











  • how would this work with spring-data-es?

    – a.k
    Nov 14 '18 at 14:24











  • Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

    – M. Deinum
    Nov 14 '18 at 16:50











  • What do you think would be the best approach to implement it by myself?

    – a.k
    Nov 15 '18 at 11:07











  • Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

    – M. Deinum
    Nov 15 '18 at 11:39
















1















I would like to update my entities upon persistence, with their creationDate/updateDate and createdBy/updatedBy.



Using JPA I would use @PrePersist and @PreUpdate and will update via a method for each.



I'm not using spring-data-jpa but using spring-data-elasticsearch.



I have normal Document entities with inheritence relationships. I want my BaseDocument to save automatically it creationDate/update and createdBy/update fields.



Iv'e found this solution- how to Spring-data MongoDB @prepersist @preupdate without using JPA
using Spring-data-commons annotation, using @CreatedBy , @CreatedDate, @LastModifiedBy, @LastModifiedDate. I don't see how this would fit here, as I want any logic to be set only when persistence is taken. this seems to work with auditing.



Another option I could do is using Spring AOP with @Before annotation, but I'm not sure how to enforce it to be done before/after persistence.



Thanks!










share|improve this question

























  • Just use the @CreatedBy etc, that has nothing to do with auditing at all.

    – M. Deinum
    Nov 14 '18 at 14:08











  • how would this work with spring-data-es?

    – a.k
    Nov 14 '18 at 14:24











  • Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

    – M. Deinum
    Nov 14 '18 at 16:50











  • What do you think would be the best approach to implement it by myself?

    – a.k
    Nov 15 '18 at 11:07











  • Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

    – M. Deinum
    Nov 15 '18 at 11:39














1












1








1








I would like to update my entities upon persistence, with their creationDate/updateDate and createdBy/updatedBy.



Using JPA I would use @PrePersist and @PreUpdate and will update via a method for each.



I'm not using spring-data-jpa but using spring-data-elasticsearch.



I have normal Document entities with inheritence relationships. I want my BaseDocument to save automatically it creationDate/update and createdBy/update fields.



Iv'e found this solution- how to Spring-data MongoDB @prepersist @preupdate without using JPA
using Spring-data-commons annotation, using @CreatedBy , @CreatedDate, @LastModifiedBy, @LastModifiedDate. I don't see how this would fit here, as I want any logic to be set only when persistence is taken. this seems to work with auditing.



Another option I could do is using Spring AOP with @Before annotation, but I'm not sure how to enforce it to be done before/after persistence.



Thanks!










share|improve this question
















I would like to update my entities upon persistence, with their creationDate/updateDate and createdBy/updatedBy.



Using JPA I would use @PrePersist and @PreUpdate and will update via a method for each.



I'm not using spring-data-jpa but using spring-data-elasticsearch.



I have normal Document entities with inheritence relationships. I want my BaseDocument to save automatically it creationDate/update and createdBy/update fields.



Iv'e found this solution- how to Spring-data MongoDB @prepersist @preupdate without using JPA
using Spring-data-commons annotation, using @CreatedBy , @CreatedDate, @LastModifiedBy, @LastModifiedDate. I don't see how this would fit here, as I want any logic to be set only when persistence is taken. this seems to work with auditing.



Another option I could do is using Spring AOP with @Before annotation, but I'm not sure how to enforce it to be done before/after persistence.



Thanks!







spring spring-data-jpa spring-data spring-data-elasticsearch






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 16:41









M. Deinum

69.5k13140149




69.5k13140149










asked Nov 14 '18 at 12:54









a.ka.k

6918




6918













  • Just use the @CreatedBy etc, that has nothing to do with auditing at all.

    – M. Deinum
    Nov 14 '18 at 14:08











  • how would this work with spring-data-es?

    – a.k
    Nov 14 '18 at 14:24











  • Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

    – M. Deinum
    Nov 14 '18 at 16:50











  • What do you think would be the best approach to implement it by myself?

    – a.k
    Nov 15 '18 at 11:07











  • Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

    – M. Deinum
    Nov 15 '18 at 11:39



















  • Just use the @CreatedBy etc, that has nothing to do with auditing at all.

    – M. Deinum
    Nov 14 '18 at 14:08











  • how would this work with spring-data-es?

    – a.k
    Nov 14 '18 at 14:24











  • Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

    – M. Deinum
    Nov 14 '18 at 16:50











  • What do you think would be the best approach to implement it by myself?

    – a.k
    Nov 15 '18 at 11:07











  • Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

    – M. Deinum
    Nov 15 '18 at 11:39

















Just use the @CreatedBy etc, that has nothing to do with auditing at all.

– M. Deinum
Nov 14 '18 at 14:08





Just use the @CreatedBy etc, that has nothing to do with auditing at all.

– M. Deinum
Nov 14 '18 at 14:08













how would this work with spring-data-es?

– a.k
Nov 14 '18 at 14:24





how would this work with spring-data-es?

– a.k
Nov 14 '18 at 14:24













Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

– M. Deinum
Nov 14 '18 at 16:50





Hmm... I thought for MongoDB and ElasticSearch those where detected and filled in the repository implementation. However they aren't apparently.

– M. Deinum
Nov 14 '18 at 16:50













What do you think would be the best approach to implement it by myself?

– a.k
Nov 15 '18 at 11:07





What do you think would be the best approach to implement it by myself?

– a.k
Nov 15 '18 at 11:07













Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

– M. Deinum
Nov 15 '18 at 11:39





Create a custom repository implementation that detects the annotations on the persisted document (and maybe Childs) and then fill them. Would only work with the default save methods on the repository not with generated ones I guess.

– M. Deinum
Nov 15 '18 at 11:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300750%2fsimilar-actions-to-prepersist-preupdate-in-spring-data-es-without-using-jpa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300750%2fsimilar-actions-to-prepersist-preupdate-in-spring-data-es-without-using-jpa%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Error while running script in elastic search , gateway timeout

Adding quotations to stringified JSON object values