Hello,

I'm having problem updating records in 1-m relationship.
I have 2 tables - Users and UsersRoles. 1 User can have 1-m UserRoles. When
I delete user - it automatically deletes all the UserRoles - so it works
well. But when I update - as I understand, it should first delete all
UsersRoles and then insert new ones.  Now it doesn't delete - only inserts
new UserRoles.
Should I delete all UsersRoles by myself before updating User or there's
something wrong with my configuration/files?

repository.xml:

<class-descriptor class="com.name.wos.users.UsersVO" table="users">
 <field-descriptor id="1" name="userId" column="US_id" jdbc-type="BIGINT"
primarykey="true" autoincrement="true"/>
 <field-descriptor id="2" name="username" column="US_username"
jdbc-type="VARCHAR"/>
 <field-descriptor id="3" name="password"  column="US_password"
jdbc-type="VARCHAR"/>
 <collection-descriptor name ="userUR"
element-class-ref="com.name.wos.users.UsersRolesVO" auto-retrieve="true"
auto-update="true" auto-delete="true">
            <inverse-foreignkey field-id-ref="2"/>
 </collection-descriptor>
</class-descriptor>

<class-descriptor class="com.name.wos.users.UsersRolesVO"
table="usersroles">
  <field-descriptor id="1" name="urId" column="UR_id" jdbc-type="BIGINT"
primarykey="true" autoincrement="true"/>
  <field-descriptor id="2" name="urUSIdFK" column="UR_US_id_FK"
jdbc-type="BIGINT"/>
  <field-descriptor id="3" name="urRLIdFK" column="UR_RL_id_FK"
jdbc-type="BIGINT"/>
</class-descriptor>


update DAO:

 public void update(ValueObject updateRecord) throws DataAccessException {
        PersistenceBroker broker = null;
        try {
            UsersVO usersVO = (UsersVO) updateRecord;
            broker = ServiceLocator.getInstance().findBroker();
            broker.beginTransaction();
            broker.store(usersVO);
            broker.commitTransaction();
        } catch (PersistenceBrokerException e) {
            broker.abortTransaction();
            e.printStackTrace();
            throw new DataAccessException("Error in UsersDAO.update()", e);
        } catch (ServiceLocatorException e) {
            throw new DataAccessException("ServiceLocatorException error in
UsersDAO.update()",e);
        } finally {
            if (broker != null) broker.close();
        }
    }


UsersVO.java:

import java.util.*;
import com.name.wos.common.ValueObject;

public class UsersVO extends ValueObject {

    private Long userId;
    private String username;
    private String password;
    private Vector userUR = new Vector(); // of type UsersRolesVO

    public Long getUserId() {
        return userId;
    }
    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public Vector getUserUR() {
        return userUR;
    }
    public void setUserUR(Vector userUR) {
        this.userUR=userUR;
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to