facebook

Update db where link table used for one to many relationship

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #305179 Reply

    DIS
    Member

    I have a small test application built that uses link tables for one to many relationship. The User object can have many roles so jpa builds the following:

    private Set<UserApplicationrole> userApplicationroles = new HashSet<UserApplicationrole>(0);

    When run, the application User objects appear to have this ‘set’ populated correctly. The problem comes when I try to change the users role. Say the initial role is guest and the new role is admin. I remove the guest UserApplicationrole from the above ‘set’ and add a admin UserApplicationrole to the userApplicationroles ‘set’. When I update using

    EntityManagerHelper.beginTransaction();
                updatedUser = new UserDAO().update(user);
                EntityManagerHelper.commit();

    The db has the new admin role but the old guest role was not removed. Remember I removed the guest role from the userApplicationroles set. I must be missing something basic but can’t figure out what it is.

    This behavior is the same with toplink and hibernate. I have other issues with hibernate. I think it is a pilot error but don’t know for sure. Is there a sample app that uses link table for one to many that might show me the way IF my mistake is not obvious.

    Any help is appreciated.

    I’m running…
    fedora: 2.6.27.21-78.2.41.fc9.i686
    MyEclipse Version: 8.0M2 installed using pulse

    #305180 Reply

    DIS
    Member

    I can identify the deleted role(s) and call

    new UserApplicationroleDAO().delete(userApprole);

    myself. I just thought these orm tools would do this for me. I wrote the code to to this and it is working. Anyone know if this is the way it should be done?

    #305202 Reply

    DIS,
    Can you share your project with us. You can send a mail to support@genuitec.com and attach your project. Please add ATTN:Shalini in the subject and refer to this post.
    Also, send us the scripts of the tables you are using.

    #305218 Reply

    DIS
    Member

    Shalini,

    Just wanted to let you know I sent the project. Let me know if you need anything else.

    Thanks

    Chuck

    #305231 Reply

    Chuck,
    I have received you files
    I shall get back to you soon

    #305463 Reply

    DIS
    Member

    This message has not been recovered.

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Update db where link table used for one to many relationship

You must be logged in to post in the forum log in