ObjectDB ObjectDB

ClassCastException: cannot be cast to com.objectdb.spi.TrackableUserType

#1

Hello,

I have a class TherapeauticDrugScreenRqst with two other nested subclasses - all using Groovy.

My first attempt to persist TherapeauticDrugScreenRqst to Objectdb 2.2.8 is successfully.

However, although my method to store the method is shown below:

    @Override
    void store( Object instance )
    {
        PersistenceManager pm = connect()
        def transaction = pm.currentTransaction()
       
        try
        {
            transaction.begin()
            pm.makePersistent( instance )
            transaction.commit()
        }
        catch( e )
        {
            SiAuto.main.logException( "com.epimss.lab.db.Connection.store(instance)", e )
        }
        finally
        {
           
            if( transaction.isActive() )
                transaction.rollback()
           
            if( !pm.isClosed() )
                pm.close()
        }
    }   // end method store

The database is NOT closed in the finally block - I still see the temporary database and if I attempt to store another instance, it tells me that there is another connection to the database.

 

If I restart the server, and attempt to store the same TherapeauticDrugScreenRqst with different field values I get the following stack trace:

ava.lang.ClassCastException: com.epimss.lab.data.toxicology.TherapeauticDrugScreenRqst cannot be cast to com.objectdb.spi.TrackableUserType
at com.objectdb.o.MMM.af(MMM.java:1025)
at com.objectdb.o.UTY.aF(UTY.java:1185)
at com.objectdb.o.UTY.aE(UTY.java:1174)
at com.objectdb.o.ENH.a(ENH.java:46)
at com.objectdb.o.STA.T(STA.java:512)
at com.objectdb.o.STM.D(STM.java:408)
at com.objectdb.o.OBM.bH(OBM.java:884)
at com.objectdb.jdo.PMImpl.bH(PMImpl.java:2186)
at com.objectdb.o.OBM.bG(OBM.java:800)
at com.objectdb.o.OBM.bE(OBM.java:715)
at com.objectdb.jpa.EMImpl.commit(EMImpl.java:274)
at javax.jdo.Transaction$commit.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at com.epimss.lab.db.Connection.store(Connection.groovy:262)
at com.epimss.lab.ui.toxicology.TherapeauticDrugScreenRqstWizard.performFinish(TherapeauticDrugScreenRqstWizard.java:170)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDialog.java:811)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:430)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.epimss.lab.handlers.OpenTherapeauticDrugScreenRqstWizardHandler.execute(OpenTherapeauticDrugScreenRqstWizardHandler.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:47)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:208)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:185)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:101)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:135)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledMenuItemRenderer$1.widgetSelected(HandledMenuItemRenderer.java:150)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:713)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:633)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:106)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:127)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
at org.eclipse.equinox.launcher.Main.main(Main.java:1384)

I don't understand why I cannot persist the second instance of the TherapeauticDrugScreenRqst when there is only three instances in the db. 

 

 

 

edit
delete
#2

Regarding closing the database - in addition to closing the PersistenceManager (or EntityManager) you have to close the PersistenceManagerFactory (or EntityManagerFactory), otherwise the database remains open (e.g. for maintaining the connection pool).

The ClassCastException might be the result of partial enhancement. Try rebuilding the project and re-enhancement of all the persistable classes. If you still get the exception please post a sample program that reproduces it.

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.