2014-07-16 75 views
0

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) 

我不知道我怎樣才能解決這個問題?

謝謝爲幫助

回答

0

最後,我會回答我的問題,並希望這將幫助別人......

多次嘗試後,我採用的解決方案有一個列表中爲每個具體類我在我的AbstractEmployeEntity管理:

@Entity 
public class AbstractEmployeEntity extends AbstractPersonneEntity { 

@OneToMany(fetch = FetchType.LAZY, mappedBy = "referent") 
private Set<HotesseEntity> listeHotesse = new HashSet<HotesseEntity>(); 

@OneToMany(fetch = FetchType.LAZY, mappedBy = "referent") 
private Set<InviteEntity> listeInvites = new HashSet<InviteEntity>(); 

@OneToMany(fetch = FetchType.LAZY, mappedBy = "referent") 
private Set<AutreClientEntity> listeAutreClients = new HashSet<AutreClientEntity>(); 

希望這會幫助別人......

0

的原因是顯而易見的:

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)] 

您的班級ch.tupperware.tuppergestion.entity.AbstractEmployeEntity未在您的表PERSONNE中找到列ID_REFERENT

你是怎麼映射你的AbstractEmployeEntity類的。如果它是一個抽象類,爲什麼不把它映射到@MappedSuperclass

+0

感謝您的快速答覆。 我發誓ID_REFERENT字段在我的表PERSONNE中。 我確實使用@MappedSuperclass映射了我的抽象類,因爲我希望能夠在AbstractEmployeEventity中擁有AbstractClientEntity的集合。 當我與@ MappedSuperclass註釋索引樹,異常 org.hibernate.AnnotationException:ch.tupperware.tuppergestion.entity.AbstractEmployeEntity.listeClients [ch.tupperware.tuppergestion:瞄準一個未映射類使用@一對多或多對多@的。 entity.AbstractClientEntity] 拋出... – bryce

+0

我建議你只註釋'@ MappedSuperclass' ** **來抽象類不具體的類。 –

+0

我試圖使用'@ MappedSuperClass'來註釋我所有的抽象類,但是現在我有類似的例外,但是在一個具體的類中: 嵌套的異常是org.hibernate.AnnotationException:使用@OneToMany或@ManyToMany以未映射的類爲目標:ch.tupperware.tuppergestion.entity.AmbassadriceEntity.listeClients [ch.tupperware.tuppergestion.entity.AbstractClientEntity] – bryce