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: enter image description here

Is this expected? I have ran out of ideas on how to make it execute only once. Please help and thanks in advance.

Guppy_00's user avatar

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.

Guppy_00's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.