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.  [ 2 posts ] 
Author Message
 Post subject: It's possible disables DELETE before insert in many-to-many?
PostPosted: Wed Dec 15, 2004 5:04 pm 
Beginner
Beginner

Joined: Wed Jan 21, 2004 10:52 pm
Posts: 27
Location: Santa Cruz do Sul - RS - Brazil
Hibernate version: 2.1.4

I know (like docs) that Hibernate performs one DELETE before insert in bidirectional (bag) many-to-many associations, like this:

The generated SQL (show_sql=true):
16:19:45,794 INFO [STDOUT] Hibernate: update Instituicao set bairro=?, cep=?, complemento=?, descricao=?, email=?, estado=?, fax=?, fone=?, localidade=?, logradouro=?, nome=?, numero=?, observacao=?, ramal=?, tipo=?, uf=?, logCriacao=?, logUltimaAtualizacao=?, logUsuario=?, logVersao=? where id=?
16:19:45,872 INFO [STDOUT] Hibernate: delete from AtividadeInstituicao where InstituicaoId=?
16:19:45,904 INFO [STDOUT] Hibernate: insert into AtividadeInstituicao (InstituicaoId, AtividadeId) values (?, ?)

However, this behavior is doubtful because all Atividade's associated with this Instituicao are affected.

Supose that BD have this relations:
Code:
Atividade | Instituicao
----------+------------
    2     |   14
    2     |   16
    3     |   16



So, I try to create a new relation between Atividade 15 and Instituicao 16, like it:
Code:
      //Initializes persistency
      p = PersistenciaFactory.getInstance(ServiceLocator.SERVIDOR_LOCAL).getPersistenciaRemota(GapeHibernateHome.class);
   
      //Load Atividade 15 and initializes bag of Instituicao (many-to-many)
      Atividade a = (Atividade) p.load(Atividade.class, new Long(15), new String[] {Atividade.CHILD_INSTITUICOES_PARCEIRAS});
   
      //Load Instituicao 16 and NOT initializes bag of Atividade (inverse many-to-many) because it's very large
      Instituicao i16 = (Instituicao) p.load(Instituicao.class, new Long(16));
      
      //Link Atividade and Instituicao
      a.addInstituicao(i16); //make bidirectional links
      
      //Update Instituicao 16
      p.update(i16);


This code realy insert a new row:
Code:
Atividade | Instituicao
----------+------------
    15    |   16

but removes these rows:
Code:
Atividade | Instituicao
----------+------------
    2     |   16
    3     |   16


and ***it are wrong!***

So, my question is: It's possible disable this DELETE before insert?
Or, How to execute this operation in other way...

Thank's for all and sorry my english, this text was translated with babelfish...

_________________
Do you still create DTO factories? Oh, no!
Try DTOptimzier now!
https://dtoptimizer.dev.java.net/


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 08, 2008 8:36 am 
Newbie

Joined: Tue Apr 08, 2008 8:27 am
Posts: 1
we are also facing same problem?? have you got any solution if so please let us know.


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