目前我的父类看起来像这样,
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 班讨厌 JDO 看起来像
@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
我知道这一点外键是当前引用或使用的.....
谁能帮我解决这个问题!
由于这是我的第一篇文章,我不知道如何正确发布,无论如何,我会解释我想要做什么
我有一个存储图像 ID 的 JDO,以及喜欢这张图片的人和讨厌这张图片的人的人员信息
为此,我创建了另外两个 JDO likesJDO 和 HatesJDO,分别存储列表。
所以,当我在 jdo 中保存有关投票的信息时,会发生以下事情
获取用户信息并将其相应地存储在用户列表中,无论是讨厌还是喜欢
将这些与图像 ID 一起添加到 UserVote JDO
终于坚持了
现在,我的问题是,当我删除 UserVote JDO 时,我希望删除 hatsJDO 和 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)