Upgrade 4.2.x -> 4.3.0 error: any types do not have a unique referenced persister

Description

To use JPA 2.1 features, I've been trying to upgrade the Hibernate suite from 4.2.6 to 4.3.0. The application throws an exception when it starts. Apparently while analyzing the entity model - not while creating the database:

any types do not have a unique referenced persister

It relates to an association annotated with @Any. I'm pretty sure I've followed the example of the documentation. Moreover it all works with 4.2.6. So maybe the semantics of @Any were changed, but the documentation wasn't yet updated ? Is it a corner case ?

The association

1 2 3 4 5 6 @Embedded @AssociationOverride(name = "method", joinColumns = @JoinColumn(name = "method_id") ) @Valid private MethodWrapper method = new MethodWrapper();

The embeddable class

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 @Embeddable public class MethodWrapper { @Any(metaColumn = @Column(name = "method_type"), fetch = FetchType.LAZY) @AnyMetaDef(idType = "long", metaType = "string", metaValues = { @MetaValue(value = "N", targetEntity = M1.class), @MetaValue(value = "M", targetEntity = M2.class), @MetaValue(value = "R", targetEntity = M3.class), @MetaValue(value = "T", targetEntity = M4.class), @MetaValue(value = "O", targetEntity = M5.class), @MetaValue(value = "D", targetEntity = M6.class), @MetaValue(value = "Z", targetEntity = M7.class), @MetaValue(value = "E", targetEntity = M8.class), @MetaValue(value = "I", targetEntity = M9.class), @MetaValue(value = "C", targetEntity = M10.class), @MetaValue(value = "G", targetEntity = M11.class)}) @JoinColumn(name = "algorithm_id") @Cascade({CascadeType.MERGE, CascadeType.PERSIST}) @Valid private Method method; public Method getMethod() { return method; } public void setMethod(final Method method) { this.method = method; } }

For convenience I've put it into an embeddable. Otherwise sooner or later somebody will make a typo in the annotations.

The stack trace

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 56 57 58 59 60 61 62 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [persistence-beans.xml]: Invocation of init method failed; nested exception is java.lang.UnsupportedOperationException: any types do not have a unique referenced persister at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1117) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:922) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) at com.acme.util.SpringContextRule$1.evaluate(SpringContextRule.java:88) at com.acme.persistence.TemporaryDatabaseRule$1.evaluate(TemporaryDatabaseRule.java:99) at org.junit.rules.RunRules.evaluate(RunRules.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) Caused by: java.lang.UnsupportedOperationException: any types do not have a unique referenced persister at org.hibernate.type.AnyType.getAssociatedJoinable(AnyType.java:501) at org.hibernate.tuple.component.AbstractCompositionAttribute$1$1.next(AbstractCompositionAttribute.java:107) at org.hibernate.tuple.component.AbstractCompositionAttribute$1$1.next(AbstractCompositionAttribute.java:82) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:147) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitCompositeDefinition(MetamodelGraphWalker.java:216) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributeDefinition(MetamodelGraphWalker.java:180) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitAttributes(MetamodelGraphWalker.java:148) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntityDefinition(MetamodelGraphWalker.java:111) at org.hibernate.persister.walking.spi.MetamodelGraphWalker.visitEntity(MetamodelGraphWalker.java:71) at org.hibernate.loader.plan.build.spi.MetamodelDrivenLoadPlanBuilder.buildRootEntityLoadPlan(MetamodelDrivenLoadPlanBuilder.java:56) at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.<init>(AbstractLoadPlanBasedEntityLoader.java:99) at org.hibernate.loader.entity.plan.EntityLoader.<init>(EntityLoader.java:134) at org.hibernate.loader.entity.plan.EntityLoader.<init>(EntityLoader.java:55) at org.hibernate.loader.entity.plan.EntityLoader$Builder.byUniqueKey(EntityLoader.java:98) at org.hibernate.loader.entity.plan.EntityLoader$Builder.byPrimaryKey(EntityLoader.java:94) at org.hibernate.loader.entity.plan.AbstractBatchingEntityLoaderBuilder.buildNonBatchingLoader(AbstractBatchingEntityLoaderBuilder.java:47) at org.hibernate.loader.entity.BatchingEntityLoaderBuilder.buildLoader(BatchingEntityLoaderBuilder.java:76) at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2506) at org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2528) at org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:4029) at org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:4011) at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:479) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) 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:288) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:310) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479) ... 27 more

I'm putting all the details into SO at:
https://stackoverflow.com/questions/21046239/hibernate-4-3-0-upgrade-any-types-do-not-have-a-unique-referenced-persister

Environment

JDK 1.6.0_43, Linux Debian Wheezy x64.

Status

Assignee

Unassigned

Reporter

Jan Goyvaerts

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.0.Final

Priority

Major
Configure