开发者

DataNucleus / NeoDatis - DB connection appears to close causing Persistable objects to be lost

Using DataNucleus I have a problem seen in the second INFO statement below (2nd entry from the bottom).

When trying to read or edit an object after persisting it with makePersistent(), I get just null values, the INFO log indicates that the object is no longer managed by the persistence manager (though I'm performing these edits immediately after the makePersistent() call).

My guess is that the connection to my datastore (NeoDatis in local embedded/file mode) is being closed, thus the persistence manager stops managing it. But I'm just using the DataNucleus org.datanucleus.jdo.JDOPersistenceManagerFactory class to create the connection.

Any idea why this might happen? Am I on the right track thinking that the closed connection messages are the problem?

FQDN's shortened, and extrane开发者_开发问答ous logs removed for brevity:

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


I love learning new things, but why does it have to be such a painful process at times? Ok right, this is an answer, not a question...

So, I did remove a key log line that would have helped others see the problem:

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

The point is that the problems above were due to the fact that I was performing the actions outside of a transaction.

Actually that was only the first step, what was really happening was that I was performing the actions against a different PersistenceManager than the transaction was started on.

I had Spring managing transactions, but I was calling jdoPersistenceManager.getPersistenceManager(), which yielded a new PersistenceManager instance (A detailed debugging session uncovered this).

I should have been using spring to get the PersistenceManager that the spring transaction defined. Ultimately that meant extending JdoDaoSupport in my DAO object.

I feel smarter now, but somehow the learning never ends.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜