Olá pessoal , gostaria de saber se o @Cascade fucniona quando utilizo HQL para fazer deleção com cláusula where.
Tenho a seguinte situação:
Tabelas:
invoice_control e invoice_contest , sendo que o relacionamento é 1:1 e a invoice_contest possui uma foreign key de invoice_control.
Minhas classes estão mapeadas da seguinte forma:
@Entity
@Table (name="INVOICE_CONTROL")
public class InvoiceControl {
....
@OneToOne(mappedBy="invoiceControl")
@Cascade(CascadeType.ALL)
private InvoiceContest invoiceContest;
...
}
@Entity
@Table (name="INVOICE_CONTEST")
public class InvoiceContest {
...
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name="FK_EBP_INVOICE_CONTROL_ID", insertable=true, updatable=true)
@Fetch(FetchMode.JOIN)
private InvoiceControl invoiceControl;
}
Estou fazendo o seguinte comando de deleção:
public void deleteWhereDateIsGreaterThanOrEqual(Date date) {
String qry = "delete from " + InvoiceControl.class.getSimpleName() + " where dueMonthYear >= :date";
Query resultQry = getSession().createQuery(qry);
resultQry.setDate("date", date);
resultQry.executeUpdate();
}
Porém da erro de constraint.
[ProcessExceptionHandler] could not execute update query
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:87)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:398)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1142)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.cpqd.billing.ebpp.model.invoicereceiving.dao.hibernate.HibernateInvoiceControlDAO.deleteWhereDa
teIsGreaterThanOrEqual(HibernateInvoiceControlDAO.java:95)
at com.cpqd.billing.ebpp.model.invoice.control.impl.EbpInvoiceControlServiceImpl.deleteInvoiceControlW
hereDateIsGreaterThanOrEqual(EbpInvoiceControlServiceImpl.java:239)
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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvoca
tion.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.jav
a:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.ja
va:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.jav
a:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy907.deleteInvoiceControlWhereDateIsGreaterThanOrEqual(Unknown Source)
at com.cpqd.billing.ebpp.invoice.control.helper.InvoiceControlHelper.deleteInvoiceControlWhereDateIsGr
eaterThanOrEqual(InvoiceControlHelper.java:483)
at com.cpqd.billing.ebpp.invoice.control.helper.InvoiceControlHelper.confirmUpdateFinhishInvoiceReceiv
ing(InvoiceControlHelper.java:474)
at com.cpqd.billing.ebpp.invoice.control.action.InvoiceControlAction.confirmUpdateFinhishInvoiceReceiv
ing(InvoiceControlAction.java:441)
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.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:280)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:216)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.billing.cadastro.configuration.ConfigurationManagerFilter.doFilter(ConfigurationManagerFil
ter.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.promus.ebpp2.security.servlet.GuardFWFilter.doFilter(GuardFWFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.util.security.servlet.SecurityFilter.doFilter(SecurityFilter.java:55)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.util.security.servlet.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:136)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.util.security.servlet.GuardLDAPFilter.doFilter(GuardLDAPFilter.java:122)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.cpqd.promus.ebpp2.security.servlet.FiltroSeguranca.doFilter(FiltroSeguranca.java:45)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.rewrite.RewriteValve.invoke(RewriteValve.java:268)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:420)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.sql.SQLException: ORA-02292: restriþÒo de integridade (EBPP02DES_SCH.FK_EINVC_ID) violada - re
gistro filho localizado
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:745)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:966)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1170)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3339)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3423)
at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeUpdate(CachedPreparedStatement.java:
95)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.jav
a:365)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:78)
... 71 more
Eu estou fazendo algo errado ou não é possível fazer deleção em cascaa com hql?
Obrigado!