-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate many-to-many batch insert/update
PostPosted: Thu Oct 18, 2007 4:30 pm 
Newbie

Joined: Sat Oct 06, 2007 4:47 am
Posts: 2
I have 2 entities User and Answer and many-to-many relationship between them:

Code:
@Entity
@Table(name="ANSWERS")
public class Answer implements java.io.Serializable {
   
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="ANSWER_ID")
    private Long id;
   
    private String name;
   
    @ManyToOne
    @JoinColumn(name="QUESTION_ID")
    private
    Question question;
   
    @ManyToMany
    @JoinColumn(name="USER_ID")
    private
    List<User> users;
    ...


Code:
@Entity
@Table(name="USERS")
public class User implements java.io.Serializable {
   
    @OneToMany(mappedBy = "user")
    private List<Task> tasks;
   
    @ManyToMany(mappedBy = "users")
    private List<Answer> answers;
   
    @Id @GeneratedValue(strategy=GenerationType.AUTO, generator="USERS_ID")
    @SequenceGenerator(sequenceName="SQ_USERS_ID", name="USERS_ID")
    @TableGenerator(name="USERS_ID")
    @Column(name="USER_ID")
    private Long id;
   
    @Temporal(value = TemporalType.TIMESTAMP)
    @Column(nullable=false, updatable=false)
    private Date created = new Date();
   
    @Temporal(value = TemporalType.TIMESTAMP)
    private Date updated;
   
    @ManyToMany(mappedBy = "users")
    private List<Group> groups;
   
    @Embedded
    @Column(nullable=false, unique=true)
    private Email email;
   
    @ManyToOne
    @JoinColumn(name="ROLE_ID")
    private Role role;
        ...


The task is bulk to insert / update records in db table in efficient way USER_ANSWER(USER_ID, ANSWER_ID) more then 100 records a time.
I have adding / updating of a big amount of records each time for each user.

What efficient way for it can you suggest?

Thx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 6:52 pm 
Newbie

Joined: Fri Nov 16, 2007 6:31 pm
Posts: 1
As to not start a new topic being our problem is similar…

We have a function in our application that takes a bulk upload which takes a root object and removes/adds to an existing many-to-many relationship it has.

When we commit our transaction we’re having very poor performance and the cause seems to be twofold.

The first problem is removal portion of the management of the relationship. The join table has 300,000-900,000 rows and the average transaction has about 4000 many-to-many modifications. Is it possible to tell hibernate to batch up the deletes to simply reduce the number of delete statements?

The second problem is we’re doing optimistic locking using the version (JPA) property and after updating this relationship hibernate has to increment the version of all objects that have been modified and it does so in a non-batched fashion, so around 4000 individual updates happen. Is it possible to batch that up?

Thanks!


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

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.