Skip to content

Commit

Permalink
try to fix "Illegal attempt to associate a ManagedEntity with two ope…
Browse files Browse the repository at this point in the history
…n persistence contexts"
  • Loading branch information
Athou committed Aug 17, 2024
1 parent 2395a26 commit e38ca66
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public void saveOrUpdate(Collection<T> models) {
models.forEach(this::saveOrUpdate);
}

public void persist(T model) {
entityManager.persist(model);
}

public T merge(T model) {
return entityManager.merge(model);
}

public T findById(Long id) {
return entityManager.find(entityClass, id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public boolean update(Feed feed, List<Entry> entries) {
feedUpdated.mark();
}

unitOfWork.run(() -> feedService.save(feed));
unitOfWork.run(() -> feedService.update(feed));

notifyOverWebsocket(unreadCountBySubscription);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ public synchronized Feed findOrCreate(String url) {
feed.setNormalizedUrl(normalizedUrl);
feed.setNormalizedUrlHash(normalizedUrlHash);
feed.setDisabledUntil(Models.MINIMUM_INSTANT);
feedDAO.saveOrUpdate(feed);
feedDAO.persist(feed);
}
return feed;
}

public void save(Feed feed) {
public void update(Feed feed) {
String normalized = FeedUtils.normalizeURL(feed.getUrl());
feed.setNormalizedUrl(normalized);
feed.setNormalizedUrlHash(Digests.sha1Hex(normalized));
feed.setLastUpdated(Instant.now());
feed.setEtagHeader(FeedUtils.truncate(feed.getEtagHeader(), 255));
feedDAO.saveOrUpdate(feed);
feedDAO.merge(feed);
}

public Favicon fetchFavicon(Feed feed) {
Expand Down

0 comments on commit e38ca66

Please sign in to comment.