ORA-02292违反约束 - 找到子记录

时间:2012-07-01 08:15:32

标签: hibernate jpa seam

父实体是许多可能的关系,当我删除父ID时我给出的例外是ORA-02292约束违规 - 找到子记录。

我的实体:

@Entity

@Table(name =" MOBEE_AGENCY")

公共类MobeeAgency实现了java.io.Serializable {

private static final long serialVersionUID = 1L;
private Long id;

private Set<MobeeAgent> mobeeAgents = new HashSet<MobeeAgent>(0);
private Set<MobeeAgcyAccounts> mobeeAgcyAccountses = new HashSet<MobeeAgcyAccounts>(
        0);

private Set<MobeeAgencyRegion> MobeeAgencyRegions = new HashSet<MobeeAgencyRegion>(0);




@Id
@GeneratedValue(generator = "MOBEE_AGENCY_SEQ")
@SequenceGenerator(name = "MOBEE_AGENCY_SEQ", sequenceName = "MOBEE_AGENCY_SEQ", allocationSize = 1)
@Column(name = "ID")
public Long getId() {
    return this.id;
}

public void setId(Long id) {
    this.id = id;
}



@OneToOne(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY)
@JoinColumn(name = "APP_ID")
public MobeeRegProcess getMobeeRegProcess() {
    return this.mobeeRegProcess;
}

public void setMobeeRegProcess(MobeeRegProcess mobeeRegProcess) {
    this.mobeeRegProcess = mobeeRegProcess;
}





@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "mobeeAgency")
public Set<MobeeAgent> getMobeeAgents() {
    return this.mobeeAgents;
}

public void setMobeeAgents(Set<MobeeAgent> mobeeAgents) {
    this.mobeeAgents = mobeeAgents;
}

@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "mobeeAgency")
public Set<MobeeAgcyAccounts> getMobeeAgcyAccountses() {
    return this.mobeeAgcyAccountses;
}

public void setMobeeAgcyAccountses(
        Set<MobeeAgcyAccounts> mobeeAgcyAccountses) {
    this.mobeeAgcyAccountses = mobeeAgcyAccountses;
}

@OneToMany(cascade = { CascadeType.PERSIST, CascadeType.REMOVE }, fetch = FetchType.LAZY, mappedBy = "mobeeAgency")
public Set<MobeeAgencyRegion> getMobeeAgencyRegions() {
    return MobeeAgencyRegions;
}

public void setMobeeAgencyRegions(Set<MobeeAgencyRegion> mobeeAgencyRegions) {
    MobeeAgencyRegions = mobeeAgencyRegions;
}

}

获得例外是:

  

13:29:56,226 INFO [STDOUT] [Mobee] - INFO 2012-07-01 13:29:56,225 []   MobeeAgencyHome - 删除机构的记录832859 13:29:56,251   INFO [STDOUT] [Mobee] - WARN 2012-07-01 13:29:56,251 []   JDBCExceptionReporter - SQL错误:2292,SQLState:23000 13:29:56,251   INFO [STDOUT] [Mobee] -ERROR 2012-07-01 13:29:56,251 []   JDBCExceptionReporter - ORA-02292:完整性约束   (KCBUSER.FK6B6B82ABC89B1A0C)违反 - 找到儿童记录   13:29:56,251 INFO [STDOUT] [Mobee] - WARN 2012-07-01 13:29:56,251 []   JDBCExceptionReporter - SQL错误:2292,SQLState:23000 13:29:56,251   INFO [STDOUT] [Mobee] -ERROR 2012-07-01 13:29:56,251 []   JDBCExceptionReporter - ORA-02292:完整性约束   (KCBUSER.FK6B6B82ABC89B1A0C)违反 - 找到儿童记录   13:29:56,253 INFO [STDOUT] [Mobee] -ERROR 2012-07-01 13:29:56,251 []   AbstractFlushingEventListener - 无法同步数据库状态   与会话org.hibernate.exception.ConstraintViolationException:   无法执行JDBC批量更新   org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)     在   org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)     在   org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)     在   org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)     在   org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)     在   org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)     在   org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2479)     在   org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2697)     在   org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:74)     在org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)at   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)     在   org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:146)     在   org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)     在   org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)     在org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)at   org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:296)     在   org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)     在org.jboss.seam.framework.EntityHome.update(EntityHome.java:64)at   com.manam.mobee.agency.MobeeAgencyHome.update(MobeeAgencyHome.java:2599)     在   com.manam.mobee.agency.MobeeAgencyHome.processUserDecision(MobeeAgencyHome.java:2465)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.jboss.seam.util.Reflections.invoke(Reflections.java:22)at   org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)     在   org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:56)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.transaction.TransactionInterceptor $ 1.work(TransactionInterceptor.java:97)     在org.jboss.seam.util.Work.workInTransaction(Work.java:47)at   org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)     在   org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)     在   org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)     在   org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)     在   org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)     在   com.manam.mobee.agency.MobeeAgencyHome _ $$ _ javassist_seam_15.processUserDecision(MobeeAgencyHome _ $$ _ javassist_seam_15.java)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at   sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at   java.lang.reflect.Method.invoke(未知来源)at   org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)     在   org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280)     在   org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)     在   org.jboss.el.parser.AstMethodSuffix.invoke(AstMethodSuffix.java:65)     在org.jboss.el.parser.AstValue.invoke(AstValue.java:96)at   org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)     在   com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)     在   javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)     在   com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)     在javax.faces.component.UICommand.broadcast(UICommand.java:383)at   org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:55)     在   org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:324)     在   org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:299)     在   org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:256)     在   org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:469)     在   com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)     在   com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)     在   com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:530)at at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)     在   org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)     在   org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)     在   org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)     在org.jboss.seam.web.RewriteFilter.process(RewriteFilter.java:98)     在org.jboss.seam.web.RewriteFilter.doFilter(RewriteFilter.java:57)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在   org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在   org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在   org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)     在org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)     在   org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)     在org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)at at   org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)at   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)     在   org.jboss.seam.servlet.SeamFilter $ FilterChainImpl.doFilter(SeamFilter.java:69)     在org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:   13:29:56,253 INFO [STDOUT] 158)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)     在   org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)     在   org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)     在   org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)     在   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)     在   org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:583)     在   org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:446)     在java.lang.Thread.run(未知来源)引起:   java.sql.BatchUpdateException:ORA-02292:完整性约束   (KCBUSER.FK6B6B82ABC89B1A0C)违规 - 找到儿童记录

2 个答案:

答案 0 :(得分:1)

如果您想在删除实体时移除您的孩子

@Cascade(DELETE_ORPHAN)

如果你可以做JPA 2

@OneToMany(orphanRemoval =真)

答案 1 :(得分:1)

请检查:

select distinct lvl cleanup_order, t1 clean_table, t2 to_clean_table 
from 
(SELECT level lvl, t2, t1, i2, c1, c2
FROM
  (
    SELECT c1.owner, c1.table_name t1, c2.table_name t2, c2.index_name i2,
      c1.constraint_name c1, c2.constraint_name c2
    FROM user_constraints c1, user_constraints c2
    WHERE c1.constraint_type = 'R'
    AND c1.r_constraint_name = c2.constraint_name
    AND c1.r_owner           = c2.owner
  )
  ov
  START WITH t2       in ('YOUR_TABLE_YOU_WANT_DELETE')  ---List tables which have to be cleaned.
  CONNECT BY prior T1 = T2) lvl
 -- where t1 is not NULL
  order by lvl desc, to_clean_table;