I am trying to create a "simple" OneToMany and ManyToOne relation. And I get following Exception:
Caused by: java.lang.ClassCastException: org.hibernate.mapping.ManyToOne cannot be cast to org.hibernate.mapping.Component at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:464) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.mapping.PersistentClass.getRecursiveProperty(PersistentClass.java:420) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:758) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:719) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:54) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1655) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1623) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final] at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:338) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.3.2.RELEASE.jar:4.3.2.RELEASE] ... 39 common frames omitted
Is someone able to tell me what I am doing wrong?
Below you can find my two entities.
Thank you in advanced.
import javax.persistence.OneToMany;
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"questionGroupID","questionID"})})
public class QuestionGroupEntity implements Serializable{
private static final long serialVersionUID = 1796640204447018439L;
@Id
@NotEmpty
@Column(name="question_group_id")
private String questionGroupID;
@NotEmpty
private String label;
@NotEmpty
private String questionID;
@OneToMany(fetch=FetchType.EAGER,targetEntity=QuestionGroupMappingEntity.class,mappedBy="questionGroup")
List<QuestionGroupMappingEntity> questionGroupMappings;
AND
import javax.persistence.ManyToOne;
@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"questionGroupID","questionID","answerID"})})
public class QuestionGroupMappingEntity implements Serializable {
private static final long serialVersionUID = 8437546139229082305L;
@Id
@SequenceGenerator(name="groupMappingIDGenerator")
@GeneratedValue(generator="groupMappingIDGenerator",strategy=GenerationType.AUTO)
private String groupMappingID;
@NotEmpty
private String questionID;
@NotEmpty
private String questionGroupID;
@NotEmpty
private String answerID;
@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="question_group_id")
private QuestionGroupEntity questionGroup;