We're updating the issue view to help you get more done. 

AnnotationException when @MapKey refers to a column mapped in @Embeddable: @ElementCollection (one to many embeddables)

Description

There's a problem mapping an @Embeddable as @ElementCollection (one to many) with an Enum as @MapKey (Hibernate 5.3.6.Final):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 public enum Type { TEL, FAX, MOBILE; } @Embeddable public class PhoneNumber implements Serializable { private static final long serialVersionUID = 1L; @Basic(optional=false) @Column(name="contact_id", insertable=false, updatable=false) private Integer contactId; @Enumerated(EnumType.STRING) @Basic(optional=false) @Column private Type type = Type.MOBILE; @Basic(optional=false) @Column(name="country_dial_code") private Integer countryDialCode; @Basic(optional=false) @Column(name="area_code") private Integer areaCode; @Basic(optional=false) @Column(name="subscriber_nbr") private Integer subscriberNbr; ... } @Entity @Table(name="Contacts") public abstract class Contact implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) @Column private Integer id; @ElementCollection @CollectionTable(name="PhoneNumbers", joinColumns={@JoinColumn(name="contact_id", referencedColumnName="id")}) @MapKey(name="type") // not @MapKeyColumn, that works! @MapKeyEnumerated(EnumType.STRING) private Map<Type, PhoneNumber> phoneNumbers; ... }

This fails with:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 16:13:28,788 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 72) MSC000001: Failed to start service jboss.persistenceunit."bbstats-0.1.war#BBStatsPU": org.jboss.msc.service.StartException in service jboss.persistenceunit."bbstats-0.1.war#BBStatsPU": org.hibernate.AnnotationException: Associated class not found: net.bbstats.entity.PhoneNumber at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:195) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:125) at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:650) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:209) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378) at java.lang.Thread.run(Thread.java:748) at org.jboss.threads.JBossThread.run(JBossThread.java:485) Caused by: org.hibernate.AnnotationException: Associated class not found: net.bbstats.entity.PhoneNumber at org.hibernate.cfg.annotations.MapBinder.bindKeyFromAssociationTable(MapBinder.java:168) at org.hibernate.cfg.annotations.MapBinder.access$000(MapBinder.java:66) at org.hibernate.cfg.annotations.MapBinder$1.secondPass(MapBinder.java:101) at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1696) at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1664) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:287) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935) at org.jboss.as.jpa.hibernate5.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:167) ... 9 more 16:13:28,788 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "bbstats-0.1.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.persistenceunit.\"bbstats-0.1.war#BBStatsPU\"" => "org.hibernate.AnnotationException: Associated class not found: net.bbstats.entity.PhoneNumber Caused by: org.hibernate.AnnotationException: Associated class not found: net.bbstats.entity.PhoneNumber"}}

Here's another use case:

https://stackoverflow.com/questions/49940382/annotationexception-when-mapkey-refers-to-a-column-mapped-in-embeddable-map-val

Environment

Hibernate 5.3.6, MySQL 8.0, WildFly 14.0.1.Final

Status

Assignee

Gail Badner

Reporter

Ka Wu

Fix versions

None

backPortable

Backport?

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.3.6
5.4.1

Priority

Major