-->
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: Problem with many-to-many association
PostPosted: Thu Nov 27, 2008 9:37 am 
Newbie

Joined: Tue Nov 25, 2008 12:18 pm
Posts: 1
Good morning everyone,

I'm experincing a problem with hibernate and many-to-many relations. I have the following situation:
Quote:
Tables relations

USUARIO (N) -----> (1) USU_EAG (1) ------> (N) EVENTO_AGENDA



And I have this hibernate mapped XML:

Usuario.hbm.xml

Code:
<idbag name="eventosAgenda" lazy="true" cascade="save-update"  table="USU_EAG">
   <collection-id type="long" column="UEA_EAG_ID">           <generator class="uuid"/>
         </collection-id>
         
         <key column="UEA_USU_ID" />         
         <many-to-many class="br.com.brt.capj.juridico.model.EventoAgenda" column="EAG_ID" fetch="join"/>
      </idbag>


EventoAgenda.hbm.xml

Code:
      <idbag name="usuarios" lazy="true" cascade="save-update" table="USU_EAG">
         <collection-id type="long" column="UEA_USU_ID">
            <generator class="uuid" />
         </collection-id>
         <key column="UEA_EAG_ID" />         
         <many-to-many
            class="br.com.brt.capj.juridico.model.Usuario" column="USU_ID" fetch="join"/>
      </idbag>


The class Usuario.java, have a collection of EventoAgenda and EventoAgenda have a collection of Usuario. This is a bidirectional relationship between this two tables. This relationship has a table named USU_EAG that makes the association of this two tables. This table has only two fields tha represents the primary key of Usuario and EventoAgenda.

Problem: The problem is that when I insert a new EventoAgenda in Usuario and makes the UPDATE/INSERT, the hibernate removes all registries in the table, for that user, and insert again wih the new one. This is causing a huge problem of performance. Can anyone help me?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 27, 2008 6:07 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The problem may be in the implementation of the getter/setter of the collections. Are you returning the same instance from the Usario.getEventosAgenda() as Hibernate passes to Usario.setEventosAgenda(). If not you will get the behavior as you describe.

By the way... Are the <idbag> mappings really working? I have no experience using <idbag>:s, but I think it seems a bit strange that you have four columns in the USU_EAG table, but each <idbag> only uses three of them. Shouldn't the column use in a <many-to-many> on one side match the <key> column of the other side? Shouldn't one of the sides be mapped with inverse="true"?


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.