#562  Exception when persisting imported issues
Closed
devcharly opened 2 years ago

I'm developing a plugin to import Redmine issues into OneDev: https://github.com/DevCharly/onedev-plugin-import-redmine

It works fine for a small amount of issues, but always throws an exception (see below) for larger amount of issues (e.g. 100). But this is not consistent. Sometimes I can import 100 issues without error. Sometimes is fails with 50 issues...

It is either thrown when persisting comments or when persisting changes. If I comment-out persisting comments and changes, I can even import ~1200 issues without any error.

The exception message is always:

failed to lazily initialize a collection of role: io.onedev.server.model.Project.issueQueryPersonalizations, could not initialize proxy - no Session

So it seems that the session was closed somewhere...

Any ideas how to fix this? Could this a problem with the embedded database?

I'm using OneDev 6.3.3 on Windows in a development environment (launched from Eclipse) with built-in database.

Imported 50 issues
Imported 100 issues
Imported 150 issues
Imported 200 issues
Imported 250 issues
Imported 299 issues
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    	at io.onedev.commons.loader.Listener.notify(Listener.java:21)
    	at io.onedev.commons.loader.DefaultListenerRegistry.post(DefaultListenerRegistry.java:69)
    	at io.onedev.server.persistence.dao.DefaultDao.persist(DefaultDao.java:54)
    	at io.onedev.server.persistence.TransactionInterceptor$1.call(TransactionInterceptor.java:23)
    	at io.onedev.server.persistence.DefaultTransactionManager$1.call(DefaultTransactionManager.java:65)
    	at io.onedev.server.persistence.DefaultSessionManager.call(DefaultSessionManager.java:79)
    	at io.onedev.server.persistence.DefaultTransactionManager.call(DefaultTransactionManager.java:60)
    	at io.onedev.server.persistence.TransactionInterceptor.invoke(TransactionInterceptor.java:18)
    	at com.devcharly.onedev.plugin.imports.redmine.ImportUtils.importIssues(ImportUtils.java:894)
    	at com.devcharly.onedev.plugin.imports.redmine.RedmineIssueImporter.doImport(RedmineIssueImporter.java:39)
    	at com.devcharly.onedev.plugin.imports.redmine.RedmineIssueImporter.doImport(RedmineIssueImporter.java:1)
    	at io.onedev.server.web.page.project.issues.imports.IssueImportPage$1.doImport(IssueImportPage.java:67)
    	at io.onedev.server.web.component.imports.ImportPanel$3$1.call(ImportPanel.java:143)
    	at io.onedev.server.web.component.imports.ImportPanel$3$1.call(ImportPanel.java:1)
    	at io.onedev.server.persistence.DefaultTransactionManager$1.call(DefaultTransactionManager.java:72)
    	at io.onedev.server.persistence.DefaultSessionManager.call(DefaultSessionManager.java:79)
    	at io.onedev.server.persistence.DefaultTransactionManager.call(DefaultTransactionManager.java:60)
    	at io.onedev.server.web.component.imports.ImportPanel$3.runTask(ImportPanel.java:139)
    	at io.onedev.server.web.component.taskbutton.TaskButton$2.call(TaskButton.java:173)
    	at io.onedev.server.web.component.taskbutton.TaskButton$2.call(TaskButton.java:1)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    	at io.onedev.server.security.SecurityUtils$1.run(SecurityUtils.java:338)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    	at java.lang.Thread.run(Thread.java:748)
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.GeneratedMethodAccessor124.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at io.onedev.commons.loader.Listener.notify(Listener.java:19)
    	... 24 more
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    	at io.onedev.commons.loader.Listener.notify(Listener.java:21)
    	at io.onedev.commons.loader.DefaultListenerRegistry.post(DefaultListenerRegistry.java:69)
    	at io.onedev.server.entitymanager.impl.DefaultIssueChangeManager.save(DefaultIssueChangeManager.java:161)
    	at io.onedev.server.persistence.TransactionInterceptor$1.call(TransactionInterceptor.java:23)
    	at io.onedev.server.persistence.DefaultTransactionManager$1.call(DefaultTransactionManager.java:65)
    	at io.onedev.server.persistence.DefaultSessionManager.call(DefaultSessionManager.java:79)
    	at io.onedev.server.persistence.DefaultTransactionManager.call(DefaultTransactionManager.java:60)
    	at io.onedev.server.persistence.TransactionInterceptor.invoke(TransactionInterceptor.java:18)
    	at io.onedev.server.entitymanager.impl.DefaultIssueChangeManager.save(DefaultIssueChangeManager.java:1)
    	at io.onedev.server.entityreference.DefaultEntityReferenceManager.addReferenceChange(DefaultEntityReferenceManager.java:77)
    	at io.onedev.server.entityreference.DefaultEntityReferenceManager.on(DefaultEntityReferenceManager.java:233)
    	at io.onedev.server.persistence.TransactionInterceptor$1.call(TransactionInterceptor.java:23)
    	at io.onedev.server.persistence.DefaultTransactionManager$1.call(DefaultTransactionManager.java:65)
    	at io.onedev.server.persistence.DefaultSessionManager.call(DefaultSessionManager.java:79)
    	at io.onedev.server.persistence.DefaultTransactionManager.call(DefaultTransactionManager.java:60)
    	at io.onedev.server.persistence.TransactionInterceptor.invoke(TransactionInterceptor.java:18)
    	... 28 more
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.GeneratedMethodAccessor185.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:498)
    	at io.onedev.commons.loader.Listener.notify(Listener.java:19)
    	... 43 more
    Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: io.onedev.server.model.Project.issueQueryPersonalizations, could not initialize proxy - no Session
    	at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:606)
    	at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:218)
    	at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:585)
    	at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:149)
    	at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:387)
    	at io.onedev.server.search.entity.QueryWatchBuilder.<init>(QueryWatchBuilder.java:30)
    	at io.onedev.server.notification.IssueNotificationManager$1.<init>(IssueNotificationManager.java:86)
    	at io.onedev.server.notification.IssueNotificationManager.on(IssueNotificationManager.java:86)
    	at io.onedev.server.persistence.TransactionInterceptor$1.call(TransactionInterceptor.java:23)
    	at io.onedev.server.persistence.DefaultTransactionManager$1.call(DefaultTransactionManager.java:65)
    	at io.onedev.server.persistence.DefaultSessionManager.call(DefaultSessionManager.java:79)
    	at io.onedev.server.persistence.DefaultTransactionManager.call(DefaultTransactionManager.java:60)
    	at io.onedev.server.persistence.TransactionInterceptor.invoke(TransactionInterceptor.java:18)
    	... 47 more
Robin Shen commented 2 years ago

Change all occurrences of dao.persist(...) as dao.getSession().saveOrUpdate(...) to see if it works

devcharly commented 2 years ago

Yes, that works.

Are there any downsides with that change? Does this still use database transaction?

The Redmine issue import plugin is based on the source code of the GitHub issues plugin. I was able to import ~500 issues (with lot of comments) from GitHub without any error. So I wonder why dao.persist(...) works with GitHub issues, but not for Redmine. Tried a lot to figure out what causes the problem.

It turns out that the text in the comments has something to do with it. If I change this line to comment.setContent(notes.replace('#', ' ')); the import of all ~1200 issues works with dao.persist(...).

Is there any processing of the comment text while persisting that could cause the problem?

Robin Shen commented 2 years ago

As you've discovered, the issue links in the comment caused the issue, and this should happen for GitHub importer also. This is a bug, and using session.saveOrUpdate is a simple workaround.

Robin Shen commented 2 years ago

You may upgrade to build #2290 and still use dao.persist

devcharly commented 2 years ago

Many thanks. It works now 😀

BTW are you interested in integrating Redmine issue import into OneDev ? If yes, I would like to submit a pull request when it is complete.

Robin Shen commented 2 years ago

This is very welcomed!

However to be included into OneDev itself, package name needs to be started with io.onedev (I can refactor that). Is this acceptable for you?

Robin Shen changed state to 'Closed' 2 years ago
Previous Value Current Value
Open
Closed
Robin Shen commented 2 years ago

Closing this now. Feel free to send a pull request if you want to include the plugin to OneDev.

issue 1 of 1
Type
Question
Priority
Normal
Assignee
Issue Votes (0)
Watchers (3)
Reference
onedev/server#562
Please wait...
Page is in error, reload to recover