Uploaded image for project: 'Hibernate ORM'
  1. HHH-5393

MappingException when @MapKeyColumn refers to a column mapped in embeddable map value

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.5.3, 4.3.6, 5.0.9
    • Fix Version/s: 5.0.10, 5.2.2, 5.1.1
    • Component/s: hibernate-core
    • Environment:
      Hibernate 3.5.3, PostgreSQL 8.4.3
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      Map<Basic, Embeddable> does not work, when the map key is a persistent field of the value. The map key shall not be represented as a separate table column, this is why the example uses @MapKey and not @MapKeyColumn.

      Example:

      @Embeddable
      public class LocalizedString {
      
          private String language;
      
          private String text;
      
      } 
      
       
      
      @Entity
      public class MultilingualString {
      
          @Id
          private long id;
      
          @ElementCollection(fetch=FetchType.EAGER)
          @MapKey(name = "language")
          @CollectionTable(schema = "jpa", name = "multilingual_string_map", 
                           joinColumns = @JoinColumn(name = "string_id"))
          private Map<String, LocalizedString> map = new HashMap<String, LocalizedString>();
      
      }
      

      Hibernate appears to expect an Entity as map value:

      org.hibernate.AnnotationException: Associated class not found: LocalizedString

      Detailed discussion of this use case:
      http://hwellmann.blogspot.com/2010/07/jpa-20-mapping-map.html

        Attachments

          Issue links

            Activity

              People

              • Votes:
                9 Vote for this issue
                Watchers:
                11 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: