kitodo-production
kitodo-production copied to clipboard
HibernateException during hierarchy export
Describe the bug
A HibernateException
occurs after repeatedly exporting the same volume of a process hierarchy. The volume itself is exported successfully, but the export of mulitvolume work it belongs to crashes with the following error in the task manager:
This is the corresponding stack trace in the logs:
[INFO ] 2022-09-21 11:11:44.682 [Vorgang exportieren: Band2] MetsService - Reading file:/usr/local/kitodo/metadata/220/meta.xml
[INFO ] 2022-09-21 11:11:44.682 [Vorgang exportieren: MultivolumeWork1] MetsService - Reading file:/usr/local/kitodo/metadata/218/meta.xml
[ERROR] 2022-09-21 11:11:44.740 [Vorgang exportieren: Band2] EmptyTask - Illegal attempt to associate a collection with two open sessions. Collection : [org.kitodo.data.database.beans.Project.folders#6]
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions. Collection : [org.kitodo.data.database.beans.Project.folders#6]
at org.hibernate.collection.internal.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:699) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:46) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:104) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.AbstractVisitor.processValue(AbstractVisitor.java:65) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:59) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.AbstractVisitor.process(AbstractVisitor.java:126) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:296) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:230) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:38) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:75) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.internal.SessionImpl.fireUpdate(SessionImpl.java:694) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:687) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.hibernate.internal.SessionImpl.update(SessionImpl.java:682) ~[hibernate-core-5.6.10.Final.jar:5.6.10.Final]
at org.kitodo.data.database.persistence.BaseDAO.initialize(BaseDAO.java:297) ~[kitodo-data-management-3.4.4-SNAPSHOT.jar:?]
at org.kitodo.data.database.beans.BaseBean.initialize(BaseBean.java:49) ~[kitodo-data-management-3.4.4-SNAPSHOT.jar:?]
at org.kitodo.data.database.beans.Project.getFolders(Project.java:214) ~[kitodo-data-management-3.4.4-SNAPSHOT.jar:?]
at org.kitodo.export.ExportDms.directoryDownload(ExportDms.java:406) ~[classes/:3.4.4-SNAPSHOT]
at org.kitodo.export.ExportDms.exportImagesAndMetsToDestinationUri(ExportDms.java:247) ~[classes/:3.4.4-SNAPSHOT]
at org.kitodo.export.ExportDms.prepareExportLocation(ExportDms.java:239) ~[classes/:3.4.4-SNAPSHOT]
at org.kitodo.export.ExportDms.startExport(ExportDms.java:201) ~[classes/:3.4.4-SNAPSHOT]
at org.kitodo.export.ExportDms.startExport(ExportDms.java:153) ~[classes/:3.4.4-SNAPSHOT]
at org.kitodo.production.helper.tasks.ExportDmsTask.run(ExportDmsTask.java:65) ~[classes/:3.4.4-SNAPSHOT]
To Reproduce Steps to reproduce the behavior:
- Create a process hierarchy (e.g. a process with at least one child process)
- Export the child process -> the child process and the parent process will be exported successfully (given correct configuration)
- Export the child process again -> the child process is exported successfully, but the export of the parent process crashes with the error message mentioned above
Expected behavior Repeated export of process hierarchies should not result in an error
Release 3.4.4-SNAPSHOT (Commit 6451791)
Error is not reproducable after tomcat restart.
Error occured again.
As far as I remember, as long as a completed task is visible in the task manager, its Thread
is referenced by the task manager and cannot be garbage-collected. If the thread is using its own Hibernate session, then this would be a logical consequence.
As far as I remember, as long as a completed task is visible in the task manager, its
Thread
is referenced by the task manager and cannot be garbage-collected. If the thread is using its own Hibernate session, then this would be a logical consequence.
@matthias-ronge Does that mean it should be possible to prevent this error by making sure the previous task in the task manager is deleted (for example via the "garbage bin" icon) before trying a subsequent export?
I am not sure, it could be. But even when you remove the thread from the display, it maybe isn’t garbage-collected soon. I would expect the thread (even if finished) should do a clean session.close() or somehow disassociate any objects from the session. Maybe it must use the same session as the rest of the web application?
I think, that the error has something to do with an export over the task manager or not. I did not see this kind of error as we use the automatic export feature (asynchronousAutomaticExport = true
in kitodo_config.properties) and the export task is an automatic export task. Even manual started exports through the UI (button click or KitodoScript call) are executed by the task manager. Maybe this is helpful.