Spring Rest Controller - business validations & resolving id

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Spring Rest Controller - business validations & resolving id



We are designing rest api for our existing application using spring+jpa.



want to validate the input/request payload prior to persisting. Have found @PrePersist listener method and hope we can validate entity business validations(unique etc) and id's can be resolved in prior to persist, however had few issues


@PrePersist



EntityManager is not auto wired: trying to autowire entity manager in super Entity class like below so that entityManger object can be used in all subclasses


EntityManager



@PersistenceContext
protected EntityManager entityManager;

Understood that since the entity is not spring managed bean, entity manager object is not autowired.


@PersistenceContext
protected EntityManager entityManager;



After setting entiy object manually (as a workaround for point 1), while trying to resolve ids based on user provided values in PrePersist callback method resulted is getting same method called recursively.



any suggestion/way to implement business validation and resolving ids based on values from jason payload for rest api would greatly appreciate.



Thanks




1 Answer
1



Have implemented AOP aspect to validate the rest resources prior to persisting which is working pretty good as expected.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard