JDOFatalUserException:Persistence Manager已关闭

时间:2012-03-01 16:42:16

标签: java h2 datanucleus

我正在尝试编写一个小应用程序,以在本地H2数据库上使用DataNucleus的JDO实现。我首先删除任何现有的H2 DB,然后通过简单的连接重新创建它。

但是,我收到JDOFatalUserException: Persistence Manager has been closed错误,我不知道为什么。当我第一次调用PM(FeedDatabaseFR.java:59)时会发生这种情况:

Transaction tx=DataNucleus.PM.currentTransaction();

以下是我得到的输出:

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)

我完全不知道为什么会这样!有人有线索吗?有人有想法吗?欢迎任何帮助!感谢。

1 个答案:

答案 0 :(得分:1)

经过Google搜索后,我找到了this。我将代码更改为:

PersistenceManager PM = DataNucleus.PMF.getPersistenceManager();
Transaction tx=PM.currentTransaction();

它有效,但我不知道为什么。如何在当前方法中将调用移至getPersistenceManager()解决了这个问题?我不明白!如果有人有解释,欢迎!!!

<强>更新

我的suuuuper不好,我确实在循环中关闭了PM。