gpt4 book ai didi

java - JDOFatalUserException : Persistence Manager has been closed

转载 作者:行者123 更新时间:2023-12-01 15:30:52 25 4
gpt4 key购买 nike

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

但是,我收到 JDOFatalUserException:持久性管理器已关闭 错误,但我不知道为什么。当我第一次调用 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)

我完全不知道为什么会发生这种情况!有人有线索吗?有人有想法建议吗?欢迎任何帮助!谢谢。

最佳答案

经过大量谷歌搜索后,我发现 this 。我将代码更改为:

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

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

更新

我的 super 糟糕,我确实在循环中关闭 PM。

关于java - JDOFatalUserException : Persistence Manager has been closed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9520286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com