title: How to programmatically add attribute converter for specific entity fields?
body: <p>Let's say I have <code>javax.persistence.AttributeConverter</code> implementation called <code>FooConverter</code> and I want to apply this converter for specific entity fields.</p>
  
  <p>If I would use the annotation approach it would look like:</p>
  
  <pre><code>@Column
  @Convert(converter = FooConverter.class)
  private String barField;
  </code></pre>
  
  <p>On orm XML mapping it would look like:</p>
  
  <pre><code>&lt;entity class="com.example.FooBarEntity"&gt;
    &lt;convert converter="com.example.FooConverter" attribute-name="barField"/&gt;
  &lt;/entity&gt;
  </code></pre>
  
  <p>However, I would like to add this converter programmatically during <code>javax.persistence.EntityManagerFactory</code> configuration.</p>
  
  <pre><code>import org.hibernate.cfg.Configuration;
  import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
  
  private EntityManagerFactory buildEntityManagerFactory() {
    Configuration config = new LocalSessionFactoryBuilder(dataSource);
    config.addAnnotatedClass(com.example.FooBarEntity.class);
    // I looking for something like config.addConverter(FooConverter, FooBarEntity, barField);
    return config.buildSessionFactory();
  }
  </code></pre>
  
  <p>There is <code>config.addAttributeConverter</code> method but it seems it only creates converter instance and not bind it to the specific entity attribute. However, I want to apply the converter only for specific <code>String</code> fields so <code>autoApply</code> is not an option.</p>