@Embeddable + @ElementCollection (one to many) with an Enum key mapped as @MapKey fails with AnnotationException


#1

Hello,

I am having a problem mapping an @Embeddable as @ElementCollection (one to many) with an Enum as @MapKey (Hibernate 5.3.6.Final):

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:

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 problem description from 2018, same result:

What’s wrong?

Karsten


#2

Looks like a bug. Since you have a replicating test case you should open a Jira issue and try to debug Hibernate to check what happens in the bindKeyFromAssociationTable method that causes this issue.


#3

There’s the one here, closed + fixed:

https://hibernate.atlassian.net/browse/HHH-5393

Do you want me to open a new one?


#4

Interesting. The bug at hand says @MapKeyColumn in the title, but it has a code example using @MapKey. The fix according to Github appears to be for @MapKeyColumn only.


#5

If you can replicate it, then it’s a new bug ir maybd a use case that was not addressed by that fix you pointed out.