-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: error inserting in collection. Many-to-Many
PostPosted: Thu Feb 17, 2005 8:59 am 
Newbie

Joined: Thu Feb 17, 2005 8:26 am
Posts: 2
Location: Brasil
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 (?, ?, ?, ?, ?)

_________________
Alexandre M. Carvalho


Top
 Profile  
 
 Post subject: the problem
PostPosted: Thu Feb 17, 2005 3:19 pm 
Newbie

Joined: Thu Feb 17, 2005 8:26 am
Posts: 2
Location: Brasil
I found the problem, buto not the solution.

We have disabled the constraint and the hibernate is trying to insert a value very strange.

<b>Generated Query</b>
insert into ADC_ATIVIDADE_CLIENTES (cliente, filial, ultima_atualizacao, usuario, atividade) values (?, ?, ?, ?, ?)
1 - > 21
2 - > 1
3 - > '2005-02-17 16:37:24'
4 - > 'USER'
5 - > 50

its seams right but without a constraint, hibernate insert in column atividade a value like 7,5000E95 instead of a Long 50. Enabling a constraint, occurs the constraint violation.

Now a new question: Why hibernate do this? How can I correct this?

Thanks

_________________
Alexandre M. Carvalho


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 21, 2005 12:09 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
It's not hibernate. It's a bug in Oracle. We had a similar problem and it was answered correctly. Oracle has a patchset available. We confirmed that 8.1.7.4 works as expected.

The Oracle Bug is #2199718


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.