Reputation: 59586
I am trying to write a small application to use DataNucleus' JDO implementation on a local H2 database. I start by deleting any existing H2 DB and recreate it with a simple connection.
However, I get a JDOFatalUserException: Persistence Manager has been closed
error and I don't know why. This happens when I perform the first call to PM (at FeedDatabaseFR.java:59
):
Transaction tx=DataNucleus.PM.currentTransaction();
Here is the output I get:
C:/Temp/FWDB/
jdbc:h2:file:C:/Temp/FWDB/FWDB;MODE=MySQL
Connection retrieved
Connection closed
Creating PersistenceManagerFactory
01-mars-2012 17:30:42 org.datanucleus.store.rdbms.table.AbstractTable create
INFO: Creating table DELETEME1330619442915
01-mars-2012 17:30:42 org.datanucleus.store.rdbms.table.AbstractTable drop
INFO: Dropping table DELETEME1330619442915
01-mars-2012 17:30:42 org.datanucleus.store.rdbms.RDBMSStoreManager initialiseSchema
INFO: Initialising Catalog "fwdb", Schema "public" using "None" auto-start option
01-mars-2012 17:30:42 org.datanucleus.store.rdbms.RDBMSStoreManager initialiseSchema
INFO: Catalog "fwdb", Schema "public" initialised - managing 0 classes
01-mars-2012 17:30:42 org.datanucleus.NucleusContext logConfiguration
INFO: ================= Persistence Configuration ===============
01-mars-2012 17:30:42 org.datanucleus.NucleusContext logConfiguration
INFO: DataNucleus Persistence Factory - Vendor: "DataNucleus" Version: "3.0.0.release"
01-mars-2012 17:30:42 org.datanucleus.NucleusContext logConfiguration
INFO: DataNucleus Persistence Factory initialised for datastore URL="jdbc:h2:file:C:/Temp/FWDB/FWDB;MODE=MySQL" driver="org.h2.Driver" userName="sa"
01-mars-2012 17:30:42 org.datanucleus.NucleusContext logConfiguration
INFO: ===========================================================
PersistenceManagerFactory is not null
Creating PersistenceManager
01-mars-2012 17:30:42 org.datanucleus.api.jdo.metadata.JDOMetaDataManager <init>
INFO: Registering listener for metadata initialisation
PersistenceManager is not null
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOMetaDataManager$MetaDataRegisterClassListener registerClass
INFO: Listener found initialisation for persistable class net.dwst.findword.DataNucleus.RawBeginItem
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOAnnotationReader processClassAnnotations
INFO: Class "net.dwst.findword.DataNucleus.RawBeginItem" has been specified with JDO annotations so using those.
01-mars-2012 17:30:43 org.datanucleus.store.StoreDataManager registerStoreData
INFO: Managing Persistence of Class : net.dwst.findword.DataNucleus.RawBeginItem [Table : RAWBEGINITEM, InheritanceStrategy : new-table]
01-mars-2012 17:30:43 org.datanucleus.store.rdbms.table.AbstractTable create
INFO: Creating table RAWBEGINITEM
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOMetaDataManager$MetaDataRegisterClassListener registerClass
INFO: Listener found initialisation for persistable class net.dwst.findword.DataNucleus.RawEndItem
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOAnnotationReader processClassAnnotations
INFO: Class "net.dwst.findword.DataNucleus.RawEndItem" has been specified with JDO annotations so using those.
01-mars-2012 17:30:43 org.datanucleus.store.StoreDataManager registerStoreData
INFO: Managing Persistence of Class : net.dwst.findword.DataNucleus.RawEndItem [Table : RAWENDITEM, InheritanceStrategy : new-table]
01-mars-2012 17:30:43 org.datanucleus.store.rdbms.table.AbstractTable create
INFO: Creating table RAWENDITEM
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOMetaDataManager$MetaDataRegisterClassListener registerClass
INFO: Listener found initialisation for persistable class net.dwst.findword.DataNucleus.RawContainItem
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOAnnotationReader processClassAnnotations
INFO: Class "net.dwst.findword.DataNucleus.RawContainItem" has been specified with JDO annotations so using those.
01-mars-2012 17:30:43 org.datanucleus.store.StoreDataManager registerStoreData
INFO: Managing Persistence of Class : net.dwst.findword.DataNucleus.RawContainItem [Table : RAWCONTAINITEM, InheritanceStrategy : new-table]
01-mars-2012 17:30:43 org.datanucleus.store.rdbms.table.AbstractTable create
INFO: Creating table RAWCONTAINITEM
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOMetaDataManager$MetaDataRegisterClassListener registerClass
INFO: Listener found initialisation for persistable class net.dwst.findword.DataNucleus.RawMadeOfItem
01-mars-2012 17:30:43 org.datanucleus.api.jdo.metadata.JDOAnnotationReader processClassAnnotations
INFO: Class "net.dwst.findword.DataNucleus.RawMadeOfItem" has been specified with JDO annotations so using those.
01-mars-2012 17:30:43 org.datanucleus.store.StoreDataManager registerStoreData
INFO: Managing Persistence of Class : net.dwst.findword.DataNucleus.RawMadeOfItem [Table : RAWMADEOFITEM, InheritanceStrategy : new-table]
01-mars-2012 17:30:43 org.datanucleus.store.rdbms.table.AbstractTable create
INFO: Creating table RAWMADEOFITEM
Exception in thread "main" javax.jdo.JDOFatalUserException: Persistence Manager has been closed
at org.datanucleus.api.jdo.JDOPersistenceManager.assertIsOpen(JDOPersistenceManager.java:2193)
at org.datanucleus.api.jdo.JDOPersistenceManager.currentTransaction(JDOPersistenceManager.java:383)
at net.dwst.findword.FR.FeedDatabaseFR.main(FeedDatabaseFR.java:59)
I have absolutely no idea why this happens! Anyone has a clue? Anyone has ideas to suggest? Any help is welcome! Thanks.
Upvotes: 0
Views: 1389
Reputation: 59586
After Googling a lot, I found this. I changed my code to:
PersistenceManager PM = DataNucleus.PMF.getPersistenceManager();
Transaction tx=PM.currentTransaction();
It works, but I don't know why. How come moving the call to getPersistenceManager()
in this current method solves this issue? I don't get it !!! If anyone has an explanation it is welcome !!!
UPDATE
My suuuuper bad, I am indeed closing the PM in a loop.
Upvotes: 2