我正在嘗試創建一個新對象Session並將其保存到數據庫中。它有一個對象User的持久變量。我查詢了要添加到會話中的用戶的數據庫。如果用戶的密碼不匹配「hello」(現在很明顯),請停止。如果有,創建一個新會話,設置常規變量並添加sOwner(只需設置Session的用戶變量)。與此類似,代碼工作,但不檢查密碼...讀取持久對象的變量可防止將其添加到對象中
try {
Query u = pm.newQuery(User.class); //Query for user
u.setFilter("email == eaddr");
u.declareImports("import java.lang.String");
u.declareParameters("String eaddr");
@SuppressWarnings("unchecked")
List<User> res = (List<User>)u.execute(email);
sOwner = res.get(0);
//if (!sOwner.getPassword().equals("hello")) { // comment out
//throw new Exception("password not correct"); // these three lines
//} // and it works
sNew = new Session();
sNew.setUser(sOwner);
sNew.setIpAddr(ipAddr);
sNew.setStartedOn(new Date());
sNew.setToken(token);
pm.makePersistent(sNew);
} catch (Exception e) {
}
,但沒有if語句註釋掉,最終的變化犯有這樣的錯誤:
2385571 [btpool0-0] DEBUG DataNucleus.Persistence - Object "[email protected]" (id="com.yachtcloser.server.om.Session:381") is having the value in field "startedOn" replaced by a SCO wrapper
2385571 [btpool0-0] DEBUG DataNucleus.Datastore.Native - INSERT INTO `SESSION` (`TOKEN`,`STARTEDON`,`USERAGENT`,`IPADDR`,`USER_ID_OID`,`ID`) VALUES (<'90a9d90f325c3b'>,<2011-02-24 19:12:15.595>,<null>,<'127.0.0.5'>,<21>,<381>)
2385572 [btpool0-0] DEBUG DataNucleus.Datastore.Persist - Execution Time = 1 ms (number of rows = 1)
2385572 [btpool0-0] DEBUG DataNucleus.Persistence - Insert of object "[email protected]" is calling insertPostProcessing for field "com.yachtcloser.server.om.Session.user"
2385572 [btpool0-0] DEBUG DataNucleus.Persistence - Insert of object "[email protected]" is calling insertPostProcessing for field "com.yachtcloser.server.om.Session.transaction"
2385572 [btpool0-0] DEBUG DataNucleus.Datastore.Retrieve - Closing PreparedStatement [email protected]18
2385572 [btpool0-0] DEBUG DataNucleus.Persistence - Insert of object "[email protected]" is calling postInsert for field "com.yachtcloser.server.om.Session.user"
2385572 [btpool0-0] DEBUG DataNucleus.Persistence - Insert of object "[email protected]" is calling postInsert for field "com.yachtcloser.server.om.Session.transaction"
2385584 [btpool0-0] DEBUG DataNucleus.Persistence - Object "[email protected]" field "transaction" is replaced by a SCO wrapper of type "org.datanucleus.store.types.sco.backed.List" [cache-values=true, lazy-loading=true, queued-operations=false, allow-nulls=true]
2385585 [btpool0-0] DEBUG com.yachtcloser.server.DispatchServlet - Response Sent:{"cmds":[{"response":"Session 381 created by user 0"}]}
2385585 [btpool0-0] DEBUG DataNucleus.Persistence - ObjectManager internalFlush() process started - 1 dirty objects
2385585 [btpool0-0] DEBUG DataNucleus.Persistence - ObjectManager internalFlush() process finished
2385589 [btpool0-0] ERROR DataNucleus.Persistence - java.lang.NullPointerException
2385590 [btpool0-0] DEBUG DataNucleus.Persistence - Disconnecting [email protected] from StateManager[[email protected], lifecycle=P_NEW]
這裏的在NPE的堆棧跟蹤我想:
NestedThrowablesStackTrace:
java.lang.NullPointerException
at org.datanucleus.store.rdbms.sql.SQLStatementHelper.selectMemberOfSourceInStatement(SQLStatementHelper.java:723)
at org.datanucleus.store.rdbms.request.FetchRequest.processMembersOfClass(FetchRequest.java:478)
at org.datanucleus.store.rdbms.request.FetchRequest.<init>(FetchRequest.java:166)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.getFetchRequest(RDBMSPersistenceHandler.java:329)
at org.datanucleus.store.rdbms.RDBMSPersistenceHandler.fetchObject(RDBMSPersistenceHandler.java:306)
at org.datanucleus.jdo.state.JDOStateManagerImpl.loadFieldsFromDatastore(JDOStateManagerImpl.java:2028)
at org.datanucleus.jdo.state.JDOStateManagerImpl.loadUnloadedFields(JDOStateManagerImpl.java:1685)
at org.datanucleus.jdo.state.JDOStateManagerImpl.runReachability(JDOStateManagerImpl.java:3295)
at org.datanucleus.ObjectManagerImpl.performReachabilityAtCommit(ObjectManagerImpl.java:3415)
at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:3268)
at org.datanucleus.ObjectManagerImpl$2.transactionPreCommit(ObjectManagerImpl.java:324)
at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:394)
at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:279)
at org.datanucleus.jdo.JDOTransaction.commit(JDOTransaction.java:90)
at com.yachtcloser.server.UserContext.finishRequest(UserContext.java:181)
at com.yachtcloser.server.DispatchServlet.doPost(DispatchServlet.java:185)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at com.yachtcloser.server.DispatchServlet.service(DispatchServlet.java:55)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
我試着拆卸副本,比較該密碼,然後將原來的查詢結果 到會話,這沒」不管工作。下面是我不能的方式編輯會話的重要組成部分:
@PersistenceCapable(identityType=IdentityType.APPLICATION)
public class Session implements Comparable<Session> {
@PrimaryKey
@Persistent(valueStrategy=IdGeneratorStrategy.INCREMENT)
private long id;
@Persistent
private User user;
DataNucleus將核-2.2.2.jar,DataNucleus將-連接池-2.0.3.jar,DataNucleus將-googlecollections-2.2.0 -release.jar,datanucleus-jdo-query-2.2.1.jar,datanucleus-rdbms-2.2.2.jar,jdo2-api-2.3-ec.jar,datanucleus-enhancer-2.1.3.jar,asm-3.3 .jar這些是我看到的jar文件
你得到一個NPE,但不引用堆棧跟蹤,所以我們不能看到它來自哪裏 - 這將是從頭開始。同時聲明正在使用的軟件的版本以及正在使用的數據存儲 – DataNucleus 2011-02-26 15:21:50
MySql 5.1和10.10 Ubuntu,在Eclipse中開發。我添加了我所認爲的你正在談論的堆棧跟蹤。 – eric 2011-02-28 21:22:45