Adding validation for email field in User entity


I have ExtUser entity with parent class User [sec$User](super class extended) everything works fine.

Now I would like to have validation for Email field which is in User [sec$User] entity(super class) and want to make it mandatory.

How do I achieve this? because I want to send email to end user with user name and password as soon as admin creates the user.


1 Like

Maybe this can help you?

We are extending User entity which is standard entity which we can not modify at all.
Email field is in user entity so how do we apply mandatory validation?

Above link doss not help me.


Unfortunately, there is no easy way to extend existing entities with Bean Validation, but you can create a simple meta property and add your validators there in the extended entity.

Use the following trick:

@Entity(name = "demo$ExtUser")
public class ExtUser extends User {
    private static final long serialVersionUID = 1150002660073436509L;

    public void setCustomerEmail(String customerEmail) { = customerEmail;

    @Email(message = "Should be valid email")
    @Length(message = "Email should have min 3 and max 50 length", min = 3, max = 50)
    @MetaProperty(mandatory = true, related = "email")
    public String getCustomerEmail() {

As you see, we simply provide additional getter / setter instead of separate column in the database.

Then extend user-edit screen:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns=""
        <groupBox id="propertiesBox">
            <grid id="propertiesGrid">
                    <row id="propertiesRow">
                        <fieldGroup id="fieldGroupLeft">
                                <field id="customerEmail"
                                <field id="email"

Just hide existing email field and add the new one.

Thanks @artamonov

Will implement this change