# Applying a Domain to an Entity Attribute

After you have created a Domain Object, you can use it as a data type for an attribute. For example, you could create a domain named `SSNumberDomain`, and write validation code for it that ensures that the resulting data type is a string of nine characters. You could then edit the `Emp` Entity Object and use `SSNumberDomain` as the data type for the `Essnum` attribute, as shown in the following steps.

1. In the Navigation pane, right-click the `Emp` Entity Object, then choose Edit to display the Entity Object Wizard.

2. Click the Attribute Settings tab to display the Attribute Settings panel. Open the Select Attribute drop-down list and select the attribute to which you want to assign to a domain type (`Essnum` in this example).

3. Open the Type dropdown list to display a list of available data types. Choose the domain you want to use (`SSNumberDomain` in this example).

4. Click Finish to close the wizard. JDeveloper generates code to apply the domain to the attribute.

The following code, which would be used in the Entity Object's `.java` file, shows how domains enforce validation rules. This code, contrived for the sake of simplicity, takes a string as an argument and tries to create a Social Security number. If the string violates the validation logic defined in `SSNumberDomain`, an exception is thrown.

    public void createSSNumber (String newNumber) {

        try {
          SSNumberDomain SSNumber = new SSNumberDomain(newNumber);

          // The new number is OK. Continue.

          ...
        } catch (Exception e) {
          // The new number is invalid. Handle the error.
          ...
        }
    }