DataNucleus / NeoDatis - 数据库连接似乎关闭导致Persistable对象丢失

时间:2010-11-14 12:16:56

标签: java database database-connection jdo datanucleus

使用DataNucleus我在下面的第二个INFO语句中看到了一个问题(从底部开始的第二个条目)。

在使用makePersistent()持久化后尝试读取或编辑对象时,我只得到空值,INFO日志表明对象不再由持久性管理器管理(虽然我在makePersistent()电话后立即执行了这些修改。

我的猜测是我的数据存储<本地嵌入/文件模式下的NeoDatis 连接正在关闭,因此持久性管理器停止管理它。但我只是使用DataNucleus org.datanucleus.jdo.JDOPersistenceManagerFactory类来创建连接。

知道为什么会这样吗?我是否在正确的轨道上认为关闭的连接消息是问题?

FQDN缩短了,为了简洁起见删除了无关的日志:

DEBUG DataNucleus.Persistence  - Making object persistent : "a.b.c.User@22a866a9"
INFO  DataNucleus.Persistence  - Managing Persistence of Class : a.b.c.User [Table : (none), InheritanceStrategy : new-table]
DEBUG DataNucleus.Connection  - Connection added to the pool : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@28f337b, null] for key=o.dn.ExecutionContextImpl@59c12050 in factory=ConnectionFactory:tx[o.dn.s.neodatis.ConnectionFactoryImpl@3b626c6d]
DEBUG DataNucleus.Datastore  - Opening NeoDatis ODB for "neodatis:file:database/neodatis_primary_datastore.odb" : org.neodatis.odb.impl.main.LocalODB@13a183d2
DEBUG DataNucleus.Datastore.Persist  - Object "a.b.c.User@22a866a9" being inserted into NeoDatis with all reachable objects
DEBUG DataNucleus.Datastore.Persist  - Object "a.b.c.User@22a866a9" (id="15) persisted to NeoDatis
DEBUG DataNucleus.Datastore  - Committing NeoDatis ODB for "neodatis:file:database/neodatis_primary_datastore.odb" : org.neodatis.odb.impl.main.LocalODB@13a183d2
DEBUG DataNucleus.Connection  - Connection removed from the pool : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@28f337b, null] for key=o.dn.ExecutionContextImpl@59c12050 in factory=ConnectionFactory:tx[o.dn.s.neodatis.ConnectionFactoryImpl@3b626c6d]
DEBUG DataNucleus.Connection  - The connection has been closed : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@28f337b, null]
DEBUG DataNucleus.Reachability  - Performing check of objects for "persistence-by-reachability" (commit) ...
DEBUG DataNucleus.Cache  - Object "a.b.c.User@22a866a9" (id="15") added to Level 2 cache (loadedFlags="[YYYYYYY]", relationFields="null")
DEBUG DataNucleus.Transaction  - Committing [DataNucleus Transaction, ID=Xid=, enlisted resources=[]]
DEBUG DataNucleus.Lifecycle  - Object "a.b.c.User@22a866a9" (id="15") has a lifecycle change : "P_NEW"->"HOLLOW"
DEBUG DataNucleus.Transaction  - Object "a.b.c.User@22a866a9" (id="15") being evicted from transactional cache
DEBUG DataNucleus.Transaction  - Transaction committed in 7 ms
DEBUG DataNucleus.Lifecycle  - Object "a.b.c.User@22a866a9" (id="15") has a lifecycle change : "HOLLOW"->"P_NONTRANS"
DEBUG DataNucleus.Persistence  - Fetching object "a.b.c.User@22a866a9" (id=15) fields [authorities,createdFromIP,dateCreated,password,timeZoneID,username]
DEBUG DataNucleus.Datastore.Retrieve  - Object "a.b.c.User@22a866a9" (id="15") being retrieved from NeoDatis
DEBUG DataNucleus.Connection  - Connection added to the pool : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@39673d71, null] for key=o.dn.ExecutionContextImpl@59c12050 in factory=ConnectionFactory:tx[o.dn.s.neodatis.ConnectionFactoryImpl@3b626c6d]
DEBUG DataNucleus.Datastore  - Opening NeoDatis ODB for "neodatis:file:database/neodatis_primary_datastore.odb" : org.neodatis.odb.impl.main.LocalODB@621f6c18
DEBUG DataNucleus.Datastore  - Committing NeoDatis ODB for "neodatis:file:database/neodatis_primary_datastore.odb" : org.neodatis.odb.impl.main.LocalODB@621f6c18
DEBUG DataNucleus.Connection  - Connection removed from the pool : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@39673d71, null] for key=o.dn.ExecutionContextImpl@59c12050 in factory=ConnectionFactory:tx[o.dn.s.neodatis.ConnectionFactoryImpl@3b626c6d]
DEBUG DataNucleus.Connection  - The connection has been closed : [o.dn.s.neodatis.ConnectionFactoryImpl$ManagedConnectionImpl@39673d71, null]
INFO  DataNucleus.Persistence  - Request to populate fields of a.b.c.User@22a866a9 but this object is no longer managed by NeoDatis so replacing with a.b.c.User@7cf1cdfb
DEBUG DataNucleus.Datastore.Retrieve  - Execution Time = 5 ms

1 个答案:

答案 0 :(得分:1)

我喜欢学习新事物,但为什么它有时必须是一个如此痛苦的过程呢? 好吧,这是一个答案,而不是一个问题......

所以,我确实删除了一个可以帮助其他人看到问题的关键日志行:

1795 [main] INFO DataNucleus.Transaction  - Non-tx updates are being committed to the datastore

关键是上述问题是由于我在交易之外执行操作。

实际上这只是第一步,真正发生的事情是我正在针对与开始交易不同的PersistenceManager执行操作。

我有Spring管理事务,但我正在调用jdoPersistenceManager.getPersistenceManager(),它产生了一个新的PersistenceManager实例(一个详细的调试会话发现了这个)。

我应该使用spring来获取spring事务定义的PersistenceManager。最终这意味着在我的DAO对象中扩展JdoDaoSupport

我现在感觉更聪明,但不知怎的,学习永远不会结束。