-->
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.  [ 1 post ] 
Author Message
 Post subject: @ManyToMany:How to avoid the extra update in table B
PostPosted: Tue Oct 25, 2011 9:46 am 
Newbie

Joined: Mon Oct 17, 2011 1:50 pm
Posts: 5
Question: @ManyToMany:How to avoid the extra update in table B when inserting in table A,Join Table

i have two tables:

Authority , Permission they have many to many relationship

Code:
    class Authority{
   
    @ManyToMany(cascade = CascadeType.ALL)
       @JoinTable(name = "authority_permission", joinColumns = { @JoinColumn(name = "authority_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "permission_id", nullable = false, updatable = false) })
       private List<Permission> permissions = new ArrayList<Permission>(0);
   
    }


some times i need to create a new Authority and assign to it some existing permissions (insert data in authority , authority_permission only) as follows:

Code:
List<Permission> permissions=new ArrayList<Permission>;
    Permission permission=permissionDao.getPermissionById(1);
    permissions.add(permission);   
    authority.setPermissions(permissions);
    sessionFactory.getCurrentSession().save(authority);


above code, works fine, but i noticed that hibernate makes an extra update in permission table, which is not needed, since there are no changes in permission table:

Code:
    Hibernate: insert into authority (description, display_name, is_default, name, authority_id) values (?, ?, ?, ?, ?)
    Hibernate: update permission set description=?, display_name=?, name=? where permission_id=?
    Hibernate: insert into role_permission (role_id, permission_id) values (?, ?)


any ideas how to avoid this extra update ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.