-->
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.  [ 5 posts ] 
Author Message
 Post subject: I can't make an object persisted
PostPosted: Wed Dec 29, 2004 6:49 am 
Newbie

Joined: Tue Dec 28, 2004 6:11 pm
Posts: 3
Location: Brazil
Hello all,

I tryng to persist two objects.

The first one, is ValeTransporteSP and will persist the table VALE_TRANSPORTE_SP, the primary key is NUM_SEQ_REQUISICAO column and second one is ValeTransporteSPQTD and the table is VALE_TRANSPORTE_SP_QTD it's primary key are NUM_SEQ_REQUISICAO and COD_CONDUCAO columns. When I call de save method the error below is generated. The idea is when I persist the class ValeTransporteSP the class ValeTransporteSPQTD will be persisted too. Thanks in advance.



Hibernate version:
2.1.6

Mapping documents:
<class
name="dixamico.intranet.bean.ValeTransporteSP"
table="VALE_TRANSPORTE_SP">

<id
name="sequencial"
column="NUM_SEQ_REQUISICAO">
<generator class="increment"/>
</id>

<property
name="numReSolicitante"
column="NUM_RE_SOLICITANTE"/>

<property
name="numTelefoneRamal"
column="NUM_TELEFONE_RAMAL"/>

<property
name="desEmail"
column="DES_EMAIL"/>

<property
name="indOpcao"
column="IND_OPCAO"/>

<property
name="desObservacao"
column="DES_OBSERVACAO"/>

<property
name="desPercursoResTrab"
column="DES_PERCURSO_RES_TRAB"/>

<property
name="desPercursoTrabRes"
column="DES_PERCURSO_TRAB_RES"/>

<property
name="datInclusao"
insert="false"
update="false"
column="DAT_INCLUSAO"/>

<set
name="quantidadeConducoes"
cascade="save-update"
inverse="true">
<key column="NUM_SEQ_REQUISICAO"/>
<one-to-many class="dixamico.intranet.bean.ValeTransporteSPQTD"/>
</set>

</class>

<class
name="dixamico.intranet.bean.ValeTransporteSPQTD"
table="VALE_TRANSPORTE_SP_QTD">

<id
name="sequencial"
column="NUM_SEQ_REQUISICAO">
<generator class="assigned"/>
</id>

<property
name="codConducao"
column="COD_CONDUCAO"/>

<property
name="qtdViagem"
column="QTD_VIAGEM"/>

<property
name="indNovaSolicitacao"
column="IND_NOVA_SOLICITACAO"/>

<property
name="desConducaoOutros"
column="DES_CONDUCAO_OUTROS"/>

<property
name="qtdViagemOutros"
column="QTD_VIAGEM_OUTROS"/>


<many-to-one
name="parentValeTransport"
column="NUM_SEQ_REQUISICAO"
class="dixamico.intranet.bean.ValeTransporteSP"
not-null="true"
insert="false"
update="false"/>

</class>


Code between sessionFactory.openSession() and session.close():
ValeTransporteDAO dao = new ValeTransporteDAO();
ValeTransporteSP valeTransporteSP = new ValeTransporteSP();
ValeTransporteSPQTD valeTransporteSPQTD = new ValeTransporteSPQTD();

// Atribui os valores informados no formulário para o POJO que será utilizado para salvar as informações
valeTransporteSP.setSequencial(20);
valeTransporteSP.setNumReSolicitante(colaborador);
valeTransporteSP.setNumTelefoneRamal(formulario.getTelefoneSolicitante());
valeTransporteSP.setDesEmail(formulario.getEmailSolicitante());
valeTransporteSP.setIndOpcao(formulario.getOpcao());
valeTransporteSP.setDesObservacao(formulario.getObservacao());
valeTransporteSP.setDesPercursoResTrab(formulario.getResidenciaTrabalho());
valeTransporteSP.setDesPercursoTrabRes(formulario.getTrabalhoResidencia());

String qtdAtual = formulario.getValeTransporteAtual();
String qtdTodos = formulario.getValeTransporteTodos();

int posicaoInicialCodigo = 0;
int posicaoFinalCodigo;
int posicaoInicialNumeroViagens;
int posicaoFinalNumeroViagens;


try
{

session1 = sessionFactory.openSession();
trn = session1.beginTransaction();

// Laço para "quebrar" a string que contem os códigos e quantidades de vales transporte utilizados pelo colaborador
for(int i=0; i < qtdAtual.length(); i++)
{
posicaoFinalCodigo = qtdAtual.indexOf("-",posicaoInicialCodigo);
valeTransporteSPQTD.setSequencial(valeTransporteSP.getSequencial());
valeTransporteSPQTD.setCodConducao(qtdAtual.substring(posicaoInicialCodigo,posicaoFinalCodigo));
posicaoInicialNumeroViagens = posicaoFinalCodigo + 1;
posicaoFinalNumeroViagens = qtdAtual.indexOf(",",posicaoInicialNumeroViagens);
if (posicaoFinalNumeroViagens == -1)
{
valeTransporteSPQTD.setQtdViagem(qtdAtual.substring(posicaoInicialNumeroViagens,qtdAtual.length()));
valeTransporteSPQTD.setSequencial(valeTransporteSP.getSequencial());
valeTransporteSPQTD.setIndNovaSolicitacao("N");
// Here is the place where I make the association bidirectional
valeTransporteSP.addChildQuantidadeConducoes(valeTransporteSPQTD);

break;
}
valeTransporteSPQTD.setQtdViagem(qtdAtual.substring(posicaoInicialNumeroViagens,posicaoFinalNumeroViagens));
posicaoInicialCodigo = posicaoFinalNumeroViagens + 1;

valeTransporteSPQTD.setSequencial(valeTransporteSP.getSequencial());
valeTransporteSPQTD.setIndNovaSolicitacao("N");
Here is the place where I make the association bidirectional
valeTransporteSP.addChildQuantidadeConducoes(valeTransporteSPQTD);

}

session1.save(valeTransporteSP);

trn.commit();
session1.close();


Full stack trace of any exception that occurs:
SEVERE: Could not synchronize database state with session

net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)

at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)

at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:684)

at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)

at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)

at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)

at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)

at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)

at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

at dixamico.intranet.dao.ValeTransporteDAO.inserirValeTransporte(ValeTransporteDAO.java:113)

at dixamico.intranet.business.B_ValeTransporte.inserirSolicitacao(B_ValeTransporte.java:30)

at dixamico.intranet.action.ValeTransporteNovoAction.perform(ValeTransporteNovoAction.java:128)

at org.apache.struts.action.Action.execute(Action.java:420)

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:1485)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)

at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)

at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

at java.lang.Thread.run(Thread.java:534)

net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)

at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)

at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:684)

at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:642)

at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)

at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2418)

at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)

at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)

at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)

at dixamico.intranet.dao.ValeTransporteDAO.inserirValeTransporte(ValeTransporteDAO.java:113)

at dixamico.intranet.business.B_ValeTransporte.inserirSolicitacao(B_ValeTransporte.java:30)

at dixamico.intranet.action.ValeTransporteNovoAction.perform(ValeTransporteNovoAction.java:128)

at org.apache.struts.action.Action.execute(Action.java:420)

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:1485)

at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)

at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)

at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)

at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)

at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)

at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)

at java.lang.Thread.run(Thread.java:534)

Name and version of the database you are using:
Oracle 8.1.7.1.1

The generated SQL (show_sql=true):
04/12/29 08:14:34 Hibernate: insert into VALE_TRANSPORTE_SP (NUM_RE_SOLICITANTE, NUM_TELEFONE_RAMAL, DES_EMAIL, IND_OPCAO, DES_OBSERVACAO, DES_PERCURSO_RES_TRAB, DES_PERCURSO_TRAB_RES, NUM_SEQ_REQUISICAO) values (?, ?, ?, ?, ?, ?, ?, ?)

04/12/29 08:14:34 Hibernate: update VALE_TRANSPORTE_SP_QTD set COD_CONDUCAO=?, QTD_VIAGEM=?, IND_NOVA_SOLICITACAO=?, DES_CONDUCAO_OUTROS=?, QTD_VIAGEM_OUTROS=? where NUM_SEQ_REQUISICAO=?

Debug level Hibernate log excerpt:



Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 6:53 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
please use code tag

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 6:58 am 
Newbie

Joined: Tue Dec 28, 2004 6:11 pm
Posts: 3
Location: Brazil
Sorry, what do you mean with code tag?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 7:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
alt + c
look just under the subject input text
Code:
this is a code


really easier to read

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 7:06 am 
Newbie

Joined: Tue Dec 28, 2004 6:11 pm
Posts: 3
Location: Brazil
Ok, I will do this the next time. Do you undertand my problem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.