ARTICLE AD BOX
I created a custom validator called @UniqueElementsById which I am applying as an annotation to Service method parameter like:
public interface MenuDetailService { List<MenuDetail> createMenuDetails(@UniqueElementsById List<MenuDetail> menuDetails); } @Service @Validated public class DefaultMenuDetailService implements MenuDetailService { @Override @Transactional(transactionManager = CommonConfig.ENTITY_PACKAGE) public List<MenuDetail> createMenuDetails(@NotEmpty @UniformSourceId @UniqueElementsById List<MenuDetail> menuDetails) { /* ommited code for brevity */ } }The problem is, when I put a breakpoint in the isValid method of my custom validator, I notice that it is being executed twice (both execution occurs at the transfer from Controller to Service, before first line of createMenuDetails). Also, inspecting the stack trace of 1st and 2nd execution, I can see the following difference:

Is this expected? I have ran out of ideas on how to make it execute only once. Please help and thanks in advance.
3171 gold badge2 silver badges9 bronze badges
2
The solution is to remove the annotation on the implementation (Defined Locally) and just to keep the annotation on method signature in interface (Defined in Hierarchy). Now, it is only executing once.
3171 gold badge2 silver badges9 bronze badges
Explore related questions
See similar questions with these tags.
