Hi all,
My problem: nombreRol and descripcionRol are attributes for a Rol that is in the database. When I do the update (inside modificar(..)), hibernate performs 2 'delete' operations after the 'update'. I don't want these operations to perform. Maybe I have to load, the complete Rol to update before change its attributes and update? I don't know. I suppose that knowing the principal key for rol is enought for updating. It seems Hibernate do some kind of cascade updating, but I have cascade=none in the mappings.
Any help would be appreciated.
---------------
Hibernate version:
2.* (Hibernate Synchronizer 2.3.1 used)
Mapping documents:
Roles.htbm
----------------------
Code:
<hibernate-mapping package="com.jaas.example.logon.dto">
<class name="Roles" table="Roles">
<id
     column="Role"
     name="role"
     type="string"
>
     <generator class="assigned" />
</id>
<property
     column="descripcion"
     length="64"
     name="descripcion"
     not-null="false"
     type="string"
/>
     <set
          cascade="none"
          lazy="true"
          name="principalsSet"
          table="PrincipalsRoles"
     >
          <key column="Role" />
          <many-to-many class="Principals" column="PrincipalID" />
     </set>
     <set
          cascade="none"
          lazy="true"
          name="permisosSet"
          table="PermisosRoles"
     >
           <key column="Role" />
           <many-to-many class="Permisos" column="idPermiso" />
     </set>
</class>
</hibernate-mapping>
Principals.hbm
----------------------
Code:
<hibernate-mapping package="com.jaas.example.logon.dto">
<class name="Principals" table="Principals">
<id
     column="PrincipalID"
     name="principalID"
     type="string"
>
     <generator class="assigned" />
</id>
<property
     column="Password"
     length="64"
     name="password"
     not-null="true"
     type="string"
/>
<set
     cascade="none"
     lazy="true"
     name="rolesSet"
     table="PrincipalsRoles"
>
     <key column="PrincipalID" />
     <many-to-many class="Roles" column="Role" />
</set>
</class>
</hibernate-mapping>
PrincipalsRoles.hbm
-------------------------------
Code:
<hibernate-mapping package="com.jaas.example.logon.dto">
<class name="PrincipalsRoles" table="PrincipalsRoles">
<composite-id>
     <key-many-to-one
           class="Roles"
           column="Role"
           name="role"
      />
      <key-many-to-one
           class="Principals"
           column="PrincipalID"
           name="principalID"
      />
</composite-id>
</class>
</hibernate-mapping>
Name and version of the database you are using:
Ms SQLServer
The generated SQL (show_sql=true):
14:25:29,180 INFO [STDOUT] Entering Roles_facade.modificarRol()
14:25:29,180 INFO [STDOUT] Leaving Roles_facade.modificarRol()
14:25:29,210 INFO [STDOUT] Hibernate: update Roles set descripcion=? where Role=?
14:25:29,210 INFO [STDOUT] Hibernate: delete from PrincipalsRoles where Role=?
14:25:29,220 INFO [STDOUT] Hibernate: delete from PermisosRoles where Role=?
14:25:29,230 INFO [STDOUT] Cerrando la session de BD-Jaas en el finally
Some Code:
HiberRoles_facadeDAO:
-------------------------------
Code:
public void modificar(Roles rol) throws EJBException {
Transaction t = null;
Session s = null;
try {
     RolesDAO dao = new RolesDAO();
     s = _BaseRootDAO.createSession();
     t = dao.beginTransaction(s);
     dao.update(rol, s);
     dao.commitTransaction(t);
} catch (HibernateException e) {
      try {
           if (null != t) t.rollback();
      } catch (HibernateException e1) {
           throw new EJBException(e1.getMessage());
      }
} finally {
      try {
           s.disconnect();
} catch (HibernateException e1) {
           throw new EJBException(e1.getMessage());
}
}
}
GuardarRolAction:
------------------------
Code:
...
Roles rol = new Roles();
rol.setRole(nombreRol);
rol.setDescripcion(descripcionRol);
ServiceLocator sl = ServiceLocator.getInstance();
Roles_facadeHome home = (Roles_facadeHome)sl.getRemoteHome(Roles_facadeHome.JNDI_NAME, Roles_facadeHome.class);
remote.modificarRol(rol);
...