Hibernate的多態性集合映射我有我的客戶一個抽象類:與註釋
@Entity
public class AbstractClientEntity extends AbstractPersonneEntity implements Demarchable {
@Column(name="ID_REFERENT")
private AbstractEmployeEntity referent;
...
具體類看起來是這樣的:
@Entity
@DiscriminatorValue(TypePersonne.Values.INVITE)
public class InviteEntity extends AbstractClientEntity implements Invitable {
...
和
@Entity
@DiscriminatorValue(TypePersonne.Values.AUTRE)
public class AutreClientEntity extends AbstractClientEntity {
,我有我的員工擁有一組AbstractClientEntity的其他抽象類:
@Entity
public class AbstractEmployeEntity extends AbstractPersonneEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_REFERENT", nullable = false)
private MonitriceEntity monitrice = new MonitriceEntity();
@OneToMany(fetch = FetchType.LAZY, mappedBy = "referent")
private Set<AbstractClientEntity> listeClients = new HashSet<AbstractClientEntity>();
...
問題是,當我特里結構運行我的web應用程序,這將引發異常:
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory ch.tupperware.tuppergestion.dao.AbstractDao.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/config/tupper-servlet.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: ch.tupperware.tuppergestion.entity.AbstractEmployeEntity, at table: PERSONNE, for columns: [org.hibernate.mapping.Column(ID_REFERENT)]
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1055)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:825)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:767)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:685)
我不知道我怎樣才能解決這個問題?
謝謝爲幫助
感謝您的快速答覆。 我發誓ID_REFERENT字段在我的表PERSONNE中。 我確實使用@MappedSuperclass映射了我的抽象類,因爲我希望能夠在AbstractEmployeEventity中擁有AbstractClientEntity的集合。 當我與@ MappedSuperclass註釋索引樹,異常 org.hibernate.AnnotationException:ch.tupperware.tuppergestion.entity.AbstractEmployeEntity.listeClients [ch.tupperware.tuppergestion:瞄準一個未映射類使用@一對多或多對多@的。 entity.AbstractClientEntity] 拋出... – bryce
我建議你只註釋'@ MappedSuperclass' ** **來抽象類不具體的類。 –
我試圖使用'@ MappedSuperClass'來註釋我所有的抽象類,但是現在我有類似的例外,但是在一個具體的類中: 嵌套的異常是org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany以未映射的類爲目標:ch.tupperware.tuppergestion.entity.AmbassadriceEntity.listeClients [ch.tupperware.tuppergestion.entity.AbstractClientEntity] – bryce