views:

24

answers:

1

Hi, in my application I've got users which have files. The UserVO has the following mapping:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "users")
public Set<Files> getFiles()
{
    return this.files;
}

Then I have a HibernateDAO with the following update method:

public void update(T vo)
{
    try
    {
        startTransaction();
        getSession().clear();
        getSession().update(vo);
        closeTransaction();
    }
    catch (HibernateException e)
    {
        rollbackTransaction();
        e.printStackTrace();
    }
}

When some values of a user's file have changed, I want to update my file. Therefore I use:

        daoFiles.update(file); // this uses the HibernateDAO update!
        UserDAO daoUser = UserDAO.getInstance();
        daoUser.update(user); //... also a HibernateDAO update

The file's changes are saved to the database then but if I want to display the files of a user, then I cannot the changes of the files because the old values were displayed. Only if I get the fileVO directly I can see the new values. So it seems that the userVO does not recognize the update of a file.

Does anybody know were the problem is?

Best wishes!

Benny

A: 

Hi Benny,

i guess the problem is that your userVO and the database get out of sync. You could try to reload the userVO object from the database. But I would prefer to use hibernates transitive persistence feature. You can save the files by adding it to the user object and updating the user object. Take a look at transitive persistence.

klause

related questions