user15599360
user15599360

Reputation:

Is it ok to annotate with Hibernate validation annotations both DTO classes and Entities?

To reduce a chance of a bug. Or should I annotate only DTO? For example,

    public class UserDto {
        @NotNull
        @NotEmpty
        private String firstName;
        
        @NotNull
        @NotEmpty
            private String lastName;
    }

public class User extends AbstractBaseEntity {
        @NotNull
        @NotEmpty
    private String username;
    @NotNull
    @NotEmpty
    @Email
    private String email;
}

P.S. Most of the code omitted for brevity

Upvotes: 1

Views: 407

Answers (1)

Alien
Alien

Reputation: 15878

Yes it is completely ok to validate it on both.

Detailed : Spring Rest API validation should be in DTO or in entity?

Upvotes: 1

Related Questions