title: Can JPA @Converter be used in a Map Mapping using @MapKey?
body: <p>I am having trouble with Hibernate Map collection mapping where the key is a enum that has a converter that should be attached to it. </p>
  
  <p><strong>User Role Enumeration with a JPA 2.1 converter</strong></p>
  
  <pre><code>public enum UserRoleDefinition {USER,ADMIN}
  
  @Converter(autoApply = true)
  public class UserRoleDefinitionConverter implements 
               AttributeConverter&lt;UserRoleDefinition, String&gt;
  {
  
    public String convertToDatabaseColumn(UserRoleDefinition attribute)
    {
      return attribute.getName();
    }
  
  
    public UserRoleDefinition convertToEntityAttribute(String dbData)
    {
      return UserRoleDefinition.parse(dbData);
    }
  }
  </code></pre>
  
  <p><strong>UserRole Entity non essential attributes removed for clarity</strong></p>
  
  <pre><code>@Entity
  public class UserRole 
  {
       @ManyToOne
      @JoinColumn(name = "user_account_fk")
      private UserAccount userAccount; 
  
      @Column(name = "role_definition_fk")
      @Convert(converter = UserRoleDefinitionConverter.class)
      private UserRoleDefinition roleDefinition;
  }
  </code></pre>
  
  <p><strong>UserAccount Entity non essential attributes removed for clarity</strong></p>
  
  <pre><code>@Entity
  public class UserAccount 
  { 
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "userAccount", cascade = CascadeType.ALL)
      @MapKey(name = "roleDefinition")
      private Map&lt;UserRoleDefinition, UserRole&gt; userRoles = new HashMap&lt;&gt;();
  } 
  </code></pre>
  
  <p>When I run the application I get the following exception. </p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: [PersistenceUnit: test] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1225)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:119)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:853)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
      at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:150)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:318)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
      ... 44 more
  Caused by: org.hibernate.MappingException: No type name
      at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:319)
      at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
      at org.hibernate.mapping.IndexedCollection.validate(IndexedCollection.java:90)
      at org.hibernate.cfg.Configuration.validate(Configuration.java:1362)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
      ... 53 more
  </code></pre>
  
  <p>I have tried all sorts of variations of the mapping, I have traced into the hiberante source code to try to understand why things are not working. In the process I determined that the converter is registered properly with hibernate, and my configuration is correct. </p>
  
  <p>Is the mapping that i want to do above legal in JPA 2.1? if not why not? If yes any idea whats is causing me this problem? </p>