@DBLookup annotation

back to index

Action

(Available since v1.1)
Replaces the value with a different value retrieved froma database

Javadoc Ref :  Javadoc reference@DBLookup

 Input Types 1
Any
 Output Types
Depends on the retrieved column type
   

1Automatic conversion will take place if the provided input does not match any of the input classes, as described in the conversions part of the manual.

Arguments

entityName

Name of the entity or table where the search is performed

searchIn
Name of the entity property or table column where to look up the original value
replaceWith
Name of the entity property or table column from which to retrieve the new value
ifNotFound

What to do if the value is not found. Can be any of the following:

  • NotFoundPolicy.ASSIGN_NULL
  • NotFoundPolicy.DO_NOTHING
  • NotFoundPolicy.THROW_EXCEPTION,
  • NotFoundPolicy.ADD_ERROR

The default behaviour is ADD_ERROR, meaning that if the value is not found, a validation error will be logged in the error map.

message

Literal message to use if validation fails

errorCode
Error code to use if validation fails.
messageKey
Message key to use if validation fails.

 

Example

@Normalized(transform=TransformType.UPPERCASE)
@DBLookup(
    entityName="countries",
    searchIn="countryId",
    replaceWith="countryName",
    ifNotFound=NotFoundPolicy.ASSIGN_NULL
  )
private String country;