Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
I´m trying to implements many-to-many with the tables:
Atividade (Activity) - AtividadeCliente (ClientActivity) - Cliente (Client)
I tried to implement in two ways: 2 one-to-many and using composite-element. In two ways i´d had the same problem. integrity constraint (ADEB.ADC_ATV_CL_ADC_CLI_FK) violated - parent key not found
I´ve tried to execute the generated query query directly in Oracle and it works.
I already search solution with the DBA and nothing.
So I want to ask if this error could be caused by the way how hibernate works. If someone can found any solution...
Thank
Hibernate Version: 2.1.6
Mapping documents:
<hibernate-mapping>
<class
name="br.com.valecard.model.Cliente"
table="ADC_CLIENTES"
dynamic-update="false"
dynamic-insert="false">
<composite-id
name="id"
class="br.com.valecard.model.pk.PkCliente"
unsaved-value="any">
<key-property
name="codigo"
type="java.lang.Long"
column="codigo"/>
<key-property
name="filial"
type="java.lang.Long"
column="filial"/>
</composite-id>
<bag
name="atividades"
table="ADC_ATIVIDADE_CLIENTES"
lazy="true"
inverse="false"
cascade="all">
<key>
<column name="cliente"/>
<column name="filial"/>
</key>
<one-to-many
class="br.com.valecard.model.AtividadeCliente"/>
</bag>
....
</hibernate-mapping>
<hibernate-mapping>
<class
name="br.com.valecard.model.AtividadeCliente"
table="ADC_ATIVIDADE_CLIENTES"
dynamic-update="false"
dynamic-insert="false">
<composite-id
name="id"
class="br.com.valecard.model.pk.PkAtividadeCliente"
unsaved-value="any">
<key-property
name="cliente"
type="java.lang.Long"
column="cliente"/>
<key-property
name="filial"
type="java.lang.Long"
column="filial"/>
<key-property
name="atividade"
type="java.lang.Long"
column="atividade"/>
</composite-id>
<many-to-one
name="cliente"
class="br.com.valecard.model.Cliente"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property">
<column name="cliente" />
<column name="filial" />
</many-to-one>
<many-to-one
name="atividade"
class="br.com.valecard.model.Atividade"
cascade="none"
outer-join="auto"
update="false"
insert="false"
access="property"
column="atividade"
not-null="true"/>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class
name="br.com.valecard.model.Atividade"
table="ADC_ATIVIDADES"
dynamic-update="false"
dynamic-insert="false">
<id
name="id"
column="codigo"
type="java.lang.Long"
unsaved-value="null">
<generator class="assigned">
</generator>
</id>
<many-to-one
name="atividadePadrao"
class="br.com.valecard.model.Atividade"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="cod_ativ_padrao"/>
<bag
name="clientesAtividade"
lazy="true"
inverse="false"
cascade="none">
<key column="atividade">
</key>
<one-to-many
class="br.com.valecard.model.AtividadeCliente"/>
</bag>
</class>
</hibernate-mapping>
Cliente cliente = ClienteBO.get(id);
....
Atividade atividade = new Atividade();
AtividadeCliente atividadeCliente = new AtividadeCliente();
atividade = AtividadeBO.get((Long) dynaForm.get("codAtividade"));
atividadeCliente.setId(new PkAtividadeCliente());
atividadeCliente.getId().setFilial(cliente.getId().getFilial());
atividadeCliente.getId().setCliente(cliente.getId().getCodigo());
atividadeCliente.getId().setAtividade(atividade.getId());
atividadeCliente.setAtividade(atividade);
cliente.addAtividadesCliente(atividadeCliente)
Full stack trace of any exception that occurs:
java.sql.SQLException: ORA-02291: integrity constraint (ADEB.ADC_ATV_CL_ADC_CLI_FK) violated - parent key not found
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:573)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2047)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1940)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2709)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:589)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeUpdate(FilterPreparedStatement.java:71)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:468)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2419)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2241)
at br.com.valecard.persistence.dao.hibernate.HibernateDAOFactory.commitTransaction(HibernateDAOFactory.java:157)
at br.com.valecard.business.ClienteBO.update(ClienteBO.java:68)
at br.com.valecard.action.DoClienteAction.alterar(DoClienteAction.java:282)
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:324)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:196)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1158)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Name and version of the database you are using: Oracle 8i
The generated SQL (show_sql=true):
insert into ADC_ATIVIDADE_CLIENTES (ultima_atualizacao, usuario, cliente, filial, atividade) values (?, ?, ?, ?, ?)