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.xmlCode:
<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.