-->
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.  [ 3 posts ] 
Author Message
 Post subject: update operation performs a delete operation not wanted
PostPosted: Mon Dec 13, 2004 9:56 am 
Newbie

Joined: Mon Dec 13, 2004 9:15 am
Posts: 2
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
----------------------
<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
----------------------
<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
-------------------------------
<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:
-------------------------------

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:
------------------------
...
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);
...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 1:45 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
please use code tag, your post is not easy to read

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


Top
 Profile  
 
 Post subject: update operation performs a delete operation not wanted
PostPosted: Tue Dec 14, 2004 1:43 pm 
Newbie

Joined: Mon Dec 13, 2004 9:15 am
Posts: 2
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);
...


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