-->
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: multithreaded import fails due to optimistic locking?
PostPosted: Wed Sep 23, 2009 5:14 am 
Newbie

Joined: Wed Sep 23, 2009 4:56 am
Posts: 1
Hello, hope one of you can give me a hint to the right direction.

I created a batch-import with hibernate for Java.
There are basically 2 tables involved:
- ArticleGroup which contains about 200 entries already
- Article where several 100.000 entries will be imported.

Both are linked with a n:m relationship, both classes contains a version column (long) for optimistic locking.

During import I link the newly created Article to one or more ArticleGroups the usual way:

Code:
article.getGroups().add(group);
group.getArticles().add(article);


In class Article the groups are defined as follows:
Code:
   @ManyToMany(fetch = FetchType.LAZY)
   @JoinTable(name = "IDX_ARTICLE_ARTICLEGROUP", joinColumns = { @JoinColumn(referencedColumnName = "id", name = "article_id") }, inverseJoinColumns = { @JoinColumn(referencedColumnName = "id", name = "articlegroup_id") }, uniqueConstraints = { @UniqueConstraint(columnNames = {
         "article_id", "articlegroup_id" }) })
   private Set<ArticleGroup> articleGroups = new HashSet<ArticleGroup>();


in class Group the articles are defined as follows:
Code:
   @ManyToMany(mappedBy = "articleGroups", fetch = FetchType.LAZY)
   private List<Article> articles = new LinkedList<Article>();


In single threaded mode everything works perfect except the fact that the version-column of the linked Group will be incremented for each imported article which is imho not nice but does not have any technical side-effect.

Problem arises in multithreaded mode when the application reports the following exception:
Quote:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was
incorrect): [common.db.idx.ArticleGroup#243]
at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1792)


I think the exception comes from the fact that the version column of the group was incremented by another thread in the meantime. During import I do however not need the relationship from Group to articles. Does anyone have a clue how this could be solved?

Thanks in advance.


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.