JPA entitymanager remove operation is not performant

Posted by Samuel on Stack Overflow See other posts from Stack Overflow or by Samuel
Published on 2010-05-17T10:12:00Z Indexed on 2010/05/18 5:10 UTC
Read the original article Hit count: 322

Filed under:
|
|
|

When I try to do an entityManager.remove(instance) the underlying JPA provider issues a separate delete operation on each of the GroupUser entity. I feel this is not right from a performance perspective, since if a Group has 1000 users there will be 1001 calls issued to delete the entire group and itr groupuser entity.

Would it make more sense to write a named query to remove all entries in groupuser table (e.g. delete from group_user where group_id=?), so I would have to make just 2 calls to delete the group.

@Entity
@Table(name = "tbl_group")

public class Group {

    @OneToMany(mappedBy = "group", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @Cascade(value = DELETE_ORPHAN)
    private Set<GroupUser> groupUsers = new HashSet<GroupUser>(0);

© Stack Overflow or respective owner

Related posts about jpa

Related posts about hibernate