我们的项目中有以下实体映射。它在hibernate版本4.3.8之前正常工作,但是当我升级到4.3.11时,测试用例开始失败并出现以下错误。
@Entity
@Table(name = "EMPLOYEE")
public class Employee
{
@Id
@Column(name = "EMPLOYEE_ID")
private long id;
@OneToMany(mappedBy="owner", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@MapKey(name = "phoneType")
private Map<PhoneType, Phone> phones = new HashMap<PhoneType, Phone>()
...
}
@Entity
@Table(name = "PHONE")
public class Phone
{
@Id
@ManyToOne
@JoinColumn(name = "EMPLOYEE_ID", referencedColumnName = "EMPLOYEE_ID")
@NotNull
private Employee owner;
@Id
@ManyToOne
@JoinColumn(name = "PHONE_TYPE_ID", nullable = false)
@NotNull
@Fetch(FetchMode.SELECT)
private PhoneType phoneType;
@NotNull
@Column(name = "PHONE_NUMBER")
private String phoneNumber;
...
}
@Entity
@Table(name = "PHONE_TYPE")
public class PhoneType
{
@Id
@Column(name = "PHONE_TYPE_ID")
private long id;
@NotNull
@Column(name = "PHONE_TYPE")
private String phoneType;
...
}
引起:java.lang.IllegalStateException:找不到集合连接中的集合索引连接[:OneToManyPersister(com.xyz.Employee.phones)] 在org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.renderCollectionJoin(LoadQueryJoinAndFetchProcessor.java:353) 在org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.renderJoin(LoadQueryJoinAndFetchProcessor.java:163) 在org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoin(LoadQueryJoinAndFetchProcessor.java:138) 在org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoins(LoadQueryJoinAndFetchProcessor.java:133) 在org.hibernate.loader.plan.exec.internal.LoadQueryJoinAndFetchProcessor.processQuerySpaceJoins(LoadQueryJoinAndFetchProcessor.java:114) 在org.hibernate.loader.plan.exec.internal.AbstractLoadQueryDetails.generate(AbstractLoadQueryDetails.java:171) 在org.hibernate.loader.plan.exec.internal.EntityLoadQueryDetails。(EntityLoadQueryDetails.java:107) 在org.hibernate.loader.plan.exec.internal.BatchingLoadQueryDetailsFactory.makeEntityLoadQueryDetails(BatchingLoadQueryDetailsFactory.java:73) 在org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader。(AbstractLoadPlanBasedEntityLoader.java:100) 在org.hibernate.loader.entity.plan.EntityLoader。(EntityLoader.java:134) 在org.hibernate.loader.entity.plan.EntityLoader。(EntityLoader.java:55) 在org.hibernate.loader.entity.plan.EntityLoader $ Builder.byUniqueKey(EntityLoader.java:98) 在org.hibernate.loader.entity.plan.EntityLoader $ Builder.byPrimaryKey(EntityLoader.java:94) 在org.hibernate.loader.entity.plan.AbstractBatchingEntityLoaderBuilder.buildNonBatchingLoader(AbstractBatchingEntityLoaderBuilder.java:47) 在org.hibernate.loader.entity.BatchingEntityLoaderBuilder.buildLoader(BatchingEntityLoaderBuilder.java:76) 在org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2506) 在org.hibernate.persister.entity.AbstractEntityPersister.createEntityLoader(AbstractEntityPersister.java:2528) 在org.hibernate.persister.entity.AbstractEntityPersister.createLoaders(AbstractEntityPersister.java:4035) 在org.hibernate.persister.entity.AbstractEntityPersister.postInstantiate(AbstractEntityPersister.java:4017) 在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:481) 在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859) 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:857) 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:850) at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425) 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849) 在org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564) ... 44更多
SKIPPED CONFIGURATION:@BeforeMethod springTestContextBeforeTestMethod SKIPPED:testPhone