### XML

````rst
<!-- src/Acme/AdministrationBundle/Resources/config/validation.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd">

    <class name="Acme\AdministrationBundle\Entity\Service">
        <constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity">
            <option name="field">
                <value>host</value>
                <value>port</value>
            </option>
            <option name="errorPath">port</option>
            <option name="message">This port is already in use on that host.</option>
        </constraint>
    </class>

</constraint-mapping>
````

### PHP

````php
// src/Acme/AdministrationBundle/Entity/Service.php
namespace Acme\AdministrationBundle\Entity;  

use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;  

class Service  
{
    public $host;  
    public $port;

    public static function loadValidatorMetadata(ClassMetadata $metadata)
    {
        $metadata->addConstraint(new UniqueEntity(array(
            'fields'    => array('host', 'port'),
            'errorPath' => 'port',
            'message'   => 'This port is already in use on that host.',
        )));
    }
}
````