目前我的父类看起来像这样,
public class UserVotesJDO {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String mediaId;
@Persistent(dependent="true")
private LikesJDO likes;
@Persistent(dependent="true")
private HatesJDO hates;
//使用getter和setter以及其他变量 }
和我的Child类hatesJDO看起来像
@PersistenceCapable(detachable = "true")
public class HatesJDO {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private int count;
private List<UserJDO> hatesUsersList;
}
其中UserJDO是另一个子类,如下所示,
@PersistenceCapable(detachable="true")
public class UserJDO {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String userId;
@Persistent
private String userName;
@Persistent
private String fullName;
@Persistent
private String userEmail;
}
我的逻辑是,当我删除UserVote时,我不再需要那些依赖孩子的仇恨和喜欢,以及它的UserJDO 所以当我尝试删除UserVotesJDO对象时,我在控制台中收到如下警告
Delete of com.shoewars.jdo.UserVotesJDO@8b4163 needs delete of related object at com.shoewars.jdo.ShoeWarsUserVotesJDO.hates but cannot delete it direct since FK is here
我得到这一点外键是当前引用或使用的.....
任何人都可以帮我解决这个问题!
由于这是我的第一篇文章,我不知道如何正确发布,无论如何,我会解释我正在尝试做什么
我有一个JDO,它存储了一个图像ID,以及那些喜欢这个图像的人的信息以及那些讨厌这个图像的人
为此目的,我创建了两个JDO likesJDO和HatesJDO,分别存储列表。
所以,当我在jdo中保存有关投票的信息时,会发生以下事情
获取用户信息并将其相应地存储在不喜欢或喜欢的用户列表中
将这些添加到UserVote JDO以及图像ID
最后坚持下去
现在,我的问题是,当我删除UserVote JDO时,我希望删除hatesJDO和likesJDO中的那些记录,以便我添加
@Persistent(dependent="true")
private LikesJDO likes;
@Persistent(dependent="true")
private HatesJDO hates;
这些行
但是现在,这样做会出现异常
堆栈跟踪就像:com.uservote.service.UserVotesOperations updateUserVoteForMedia: Cannot read fields from a deleted object
javax.jdo.JDOUserException: Cannot read fields from a deleted object
FailedObject:com.google.appengine.api.datastore.Key:UserVotesJDO(80003)/LikesJDO(1)/UserJDO(2001)
at org.datanucleus.api.jdo.state.PersistentDeleted.transitionReadField(PersistentDeleted.java:116)
at org.datanucleus.state.AbstractStateManager.transitionReadField(AbstractStateManager.java:838)
at org.datanucleus.state.JDOStateManager.isLoaded(JDOStateManager.java:1699)
at com.uservotes.jdo.UserJDO.jdoGetuserId(UserJDO.java)
at com.uservotes.jdo.UserJDO.getUserDTO(UserJDO.java:157)
at com.uservotes.service.InstagramApiService.convertToUserDtoList(InstagramApiService.java:555)
at com.uservotes.jdo.LikesJDO.getLikesDTO(LikesJDO.java:95)
at com.uservotes.jdo.uservotesUserVotesJDO.getuservotesUserVotesDTO(uservotesUserVotesJDO.java:109)
at com.uservotes.service.UserVotesOperations.updateUserVoteForMedia(UserVotesOperations.java:242)
at com.uservotes.service.UserVotesOperations.updateUserVoteForMediaList(UserVotesOperations.java:162)
at com.uservotes.controller.UserVotesController.hanldeUpdateUserVotesRequest(UserVotesController.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:165)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:163)
at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:124)
at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:43)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:266)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:454)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:461)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:703)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:338)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:330)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:458)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)
答案 0 :(得分:0)
似乎与Lazy Load相关的东西。尝试访问like&amp;在删除之前讨厌(通过getLikes()&amp; getHates())。