1

我的域类如下:

1-音频文件参考:

@SuppressWarnings("serial")
@Entity
@Table(name = "audiofileref", catalog = "advertisedb")
public class Audiofileref implements java.io.Serializable {


    @OneToMany(fetch = FetchType.LAZY, mappedBy = "audiofileref", cascade = CascadeType.ALL)
    private Set<Adpage> adpages = new HashSet<Adpage>(0);

    }

2- 广告页:

@SuppressWarnings("serial")
@Entity
@Table(name = "adpage", catalog = "advertisedb")
public class Adpage implements java.io.Serializable {

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "audio_file_id", unique = true, nullable = true)
    private Audiofileref audiofileref;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "adpage", cascade = CascadeType.ALL)
    private Set<ImageFileRef> imageFileRefs = new HashSet<ImageFileRef>(0);

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "adpage", cascade = CascadeType.ALL)
    private Set<PageActionPlanMap> pageActionPlanMaps = new HashSet<PageActionPlanMap>(
            0); 

            }

3- ImageFileRef:

@SuppressWarnings("serial")
@Entity
@Table(name = "imagefileref", catalog = "advertisedb")
public class ImageFileRef implements java.io.Serializable {


    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_adpage", nullable = false)
    private Adpage adpage;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "PhTypeID")
    private Phonescreentype phonescreentype;

}

4- PageActionPlanMap:

@SuppressWarnings("serial")
@Entity
@Table(name = "pageactionplan_map", catalog = "advertisedb")
public class PageActionPlanMap implements java.io.Serializable {


    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "fk_adpage", nullable = false)
    private Adpage adpage;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "APID", nullable = false)
    private Actionsplan actionsplan;

}

5- 行动计划:

@SuppressWarnings("serial")
@Entity
@Table(name = "actionsplan", catalog = "advertisedb")
public class Actionsplan implements java.io.Serializable {


    @OneToMany(fetch = FetchType.LAZY, mappedBy = "actionsplan")
    private Set<PageActionPlanMap> pageActionPlanMaps = new HashSet<PageActionPlanMap>(
            0);

            }

要求:

  1. 删除Audiofileref时, Adpage中的外键设置为 null;
  2. 删除Adpage时,将删除以下内容:AudiofilerefImageFileRefPageActionPlanMap

删除 Audiofileref 时我得到了什么:

Hibernate: select adpages0_.audio_file_id as audio7_3_1_, adpages0_.pkid as pkid1_, adpages0_.pkid as pkid1_0_, adpages0_.fk_advertisement as fk6_1_0_, adpages0_.audio_file_id as audio7_1_0_, adpages0_.Description as Descript2_1_0_, adpages0_.HomePage as HomePage1_0_, adpages0_.Name as Name1_0_, adpages0_.Text as Text1_0_ from advertisedb.adpage adpages0_ where adpages0_.audio_file_id=?
Hibernate: select imagefiler0_.fk_adpage as fk6_1_2_, imagefiler0_.pkid as pkid2_, imagefiler0_.pkid as pkid9_1_, imagefiler0_.fk_adpage as fk6_9_1_, imagefiler0_.Description as Descript2_9_1_, imagefiler0_.Height as Height9_1_, imagefiler0_.Name as Name9_1_, imagefiler0_.PhTypeID as PhTypeID9_1_, imagefiler0_.Width as Width9_1_, phonescree1_.PhTypeID as PhTypeID16_0_, phonescree1_.Description as Descript2_16_0_, phonescree1_.TypeName as TypeName16_0_ from advertisedb.imagefileref imagefiler0_ left outer join advertisedb.phonescreentype phonescree1_ on imagefiler0_.PhTypeID=phonescree1_.PhTypeID where imagefiler0_.fk_adpage=?
Hibernate: select pageaction0_.fk_adpage as fk8_1_2_, pageaction0_.pkid as pkid2_, pageaction0_.pkid as pkid12_1_, pageaction0_.ActionValue as ActionVa2_12_1_, pageaction0_.APID as APID12_1_, pageaction0_.fk_adpage as fk8_12_1_, pageaction0_.MailCC as MailCC12_1_, pageaction0_.MailTo as MailTo12_1_, pageaction0_.SoftKeyName as SoftKeyN5_12_1_, pageaction0_.SoftKeyNo as SoftKeyNo12_1_, actionspla1_.APID as APID0_0_, actionspla1_.Description as Descript2_0_0_, actionspla1_.Name as Name0_0_ from advertisedb.pageactionplan_map pageaction0_ inner join advertisedb.actionsplan actionspla1_ on pageaction0_.APID=actionspla1_.APID where pageaction0_.fk_adpage=?
Hibernate: select pageaction0_.APID as APID0_2_, pageaction0_.pkid as pkid2_, pageaction0_.pkid as pkid12_1_, pageaction0_.ActionValue as ActionVa2_12_1_, pageaction0_.APID as APID12_1_, pageaction0_.fk_adpage as fk8_12_1_, pageaction0_.MailCC as MailCC12_1_, pageaction0_.MailTo as MailTo12_1_, pageaction0_.SoftKeyName as SoftKeyN5_12_1_, pageaction0_.SoftKeyNo as SoftKeyNo12_1_, adpage1_.pkid as pkid1_0_, adpage1_.fk_advertisement as fk6_1_0_, adpage1_.audio_file_id as audio7_1_0_, adpage1_.Description as Descript2_1_0_, adpage1_.HomePage as HomePage1_0_, adpage1_.Name as Name1_0_, adpage1_.Text as Text1_0_ from advertisedb.pageactionplan_map pageaction0_ inner join advertisedb.adpage adpage1_ on pageaction0_.fk_adpage=adpage1_.pkid where pageaction0_.APID=?
Hibernate: delete from advertisedb.pageactionplan_map where pkid=?
Hibernate: delete from advertisedb.pageactionplan_map where pkid=?
Hibernate: delete from advertisedb.adpage where pkid=?
Hibernate: delete from advertisedb.audiofileref where pkid=?

然后我得到以下异常,并且 Audiofileref 没有被删除:

Caused by: org.springframework.orm.hibernate3.HibernateSystemException: Found two representations of same collection: com.xeno.advertisingsuite.web.domain.Adpage.imageFileRefs; nested exception is org.hibernate.HibernateException: Found two representations of same collection: com.xeno.advertisingsuite.web.domain.Adpage.imageFileRefs
    at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:679)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:793)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:664)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy36.updatePage(Unknown Source)
    at com.xeno.advertisingsuite.web.beans.AdPageBean.saveAudioFileRef(AdPageBean.java:190)
    at com.xeno.advertisingsuite.web.beans.AdPageBean.fileListener(AdPageBean.java:149)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at org.icefaces.ace.component.fileentry.FileEntry.broadcast(FileEntry.java:306)
    ... 103 more
Caused by: org.hibernate.HibernateException: Found two representations of same collection: com.xeno.advertisingsuite.web.domain.Adpage.imageFileRefs
    at org.hibernate.engine.Collections.processReachableCollection(Collections.java:175)
    at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:60)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:124)
    at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:84)
    at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:78)
    at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:165)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
    at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:656)
    ... 120 more

请告知如何解决。

4

0 回答 0