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.