title: Configure Hibernate validation for bean
body: <p>I need to perform validation based on SQL query result.</p>
  
  <p>Query is defined as annotation - as <em>@NamedQuery</em> in my entity bean.</p>
  
  <p>According to Hibernate documentation(<a href="http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single/#example-beanvalidationeventlistener-config" rel="nofollow noreferrer">doc</a>), there is possibility to validate bean on following operations:<br>
  <em>pre-update<br>
  pre-insert<br>
  pre-delete<br></em></p>
  
  <p>looks like:</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
         ...
      &lt;event type="pre-update"&gt;
         &lt;listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/&gt;
      &lt;/event&gt;
      &lt;event type="pre-insert"&gt;
          &lt;listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/&gt;
      &lt;/event&gt;
      &lt;event type="pre-delete"&gt;
          &lt;listener class="org.hibernate.cfg.beanvalidation.BeanValidationEventListener"/&gt;
      &lt;/event&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>The question is how <strong>to connect my bean</strong> with the validation configuration, described above.</p>
  
  <p><strong>updated:</strong><br></p>
  
  <p><em>entity class</em></p>
  
  <pre><code>...
  @Entity
  @NamedQuery(name = "isValutaKursExists", query = "SELECT id FROM CurrencyRate WHERE bankId = :bankNum")
  @Table(name = "Currency")
  public class Currency {
  ...
  </code></pre>