修复:所以看来VM文件中有问题。将实体集合添加到另一个实体集合时,VM文件#if检查对象分配是否存在或未失败。这是由于这样的事实,即分配从普通的一维集合更改为二维集合。我要做的就是更改if检查,以查看赋值集合中特定的内容是否不为null。此问题显示为一个懒惰的持久性问题,但事实证明,此问题的原始原因与此无关。
编辑2:在实体的初始化方法上添加了@override,它似乎正在工作。如果有任何更改,将更新。
编辑:发现新的实体创建不是引起问题的原因,但是稍后在回去编辑分配时确实会产生问题。虽然不知道为什么,但是我认为这可能是新实体DB表和原始分配实体表之间的引用或链接。
一段时间以来,我一直在努力解决一个懒惰的休眠持久性问题,找不到适合我情况的任何东西。所用代码的背景:
系统背景
该系统基本上是LMS系统。我目前正忙于其中的一部分,您可以在其中创建作业以供学生提交。保留任务的原始实体没有更改,仍然可以工作,但是现在,如果我在保留任务一个之后仍然保留一个新实体,似乎是会话还是某些东西被重置了?新实体正确映射到数据库(检查信息是否正确地手动保存在数据库中),但是如果我通过UI返回编辑分配,则会得到以下信息:
org.apache.velocity.exception.VelocityException: Reference evaluation threw an exception at /vm/assignment/chef_assignments_instructor_new_edit_assignment.vm[line 540, column 37]
at org.apache.velocity.runtime.parser.node.ASTReference.evaluate(ASTReference.java:491)
at org.apache.velocity.runtime.parser.node.ASTAndNode.evaluate(ASTAndNode.java:104)
at org.apache.velocity.runtime.parser.node.ASTAndNode.evaluate(ASTAndNode.java:104)
at org.apache.velocity.runtime.parser.node.ASTExpression.evaluate(ASTExpression.java:62)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:85)
at org.apache.velocity.runtime.parser.node.ASTBlock.render(ASTBlock.java:72)
at org.apache.velocity.runtime.parser.node.ASTIfStatement.render(ASTIfStatement.java:87)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:336)
at org.apache.velocity.Template.merge(Template.java:328)
at org.apache.velocity.Template.merge(Template.java:235)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.performMerge(VelocityViewServlet.java:805)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.mergeTemplate(VelocityViewServlet.java:762)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doRequest(VelocityViewServlet.java:555)
at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doGet(VelocityViewServlet.java:509)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:557)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:527)
at org.sakaiproject.vm.VmServlet.includeVm(VmServlet.java:162)
at org.sakaiproject.cheftool.VelocityPortletPaneledAction.toolModeDispatch(VelocityPortletPaneledAction.java:454)
at org.sakaiproject.cheftool.ToolServlet.doGet(ToolServlet.java:234)
at org.sakaiproject.cheftool.VelocityPortletPaneledAction.doGet(VelocityPortletPaneledAction.java:1152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.sakaiproject.vm.ComponentServlet.service(ComponentServlet.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:418)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:470)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:356)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:316)
at org.sakaiproject.tool.impl.ActiveToolComponent$MyActiveTool.forward(ActiveToolComponent.java:513)
at org.sakaiproject.portal.charon.SkinnableCharonPortal.forwardTool(SkinnableCharonPortal.java:1488)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doToolBuffer(SiteHandler.java:1227)
at org.sakaiproject.portal.charon.handlers.SiteHandler.bufferContent(SiteHandler.java:1061)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doSite(SiteHandler.java:490)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doGet(SiteHandler.java:266)
at org.sakaiproject.portal.charon.handlers.SiteHandler.doGet(SiteHandler.java:154)
at org.sakaiproject.portal.charon.SkinnableCharonPortal.doGet(SkinnableCharonPortal.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:467)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:716)
at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:282)
at org.hibernate.collection.internal.PersistentSet.initializeFromCache(PersistentSet.java:145)
at org.hibernate.cache.spi.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:75)
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:160)
at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:76)
at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1933)
at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:559)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:261)
at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:555)
at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:143)
at org.hibernate.collection.internal.PersistentSet.toString(PersistentSet.java:316)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at org.sakaiproject.assignment.api.model.Assignment.toString(Assignment.java:93)
at org.apache.velocity.runtime.parser.node.ASTReference.evaluate(ASTReference.java:487)
... 70 more
现在我认为第一个错误日志是因为会话在中途重置,所以VM文件中的某些变量不存在,但是我的问题是休眠状态...
实体持续存在:
@Override
@Transactional
public void saveMarkerSetup(String context, String markerUserID, double quota, String modifier, Assignment assignmentID, Instant dateCreated) {
EntityClass entity = new EntityClass ();
entity.setContext(context);
entity.setDateCreated(dateCreated);
entity.setMarkerUserId(markerUserID);
entity.setQuotaPercentage(quota);
entity.setAssignment(assignmentID);
sessionFactory.getCurrentSession().persist(entity);
}
实体类:
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "ASN_MARKER_T")
@Data
@NoArgsConstructor
@EqualsAndHashCode(of = "id")
public class EntityClass {
@Id
@Column(name = "MARKER_ID", length = 36, nullable = false)
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@Column(name = "MARKER_USER_ID", nullable = false)
private String markerUserId;
@Column(name = "CONTEXT", length = 99, nullable = false)
private String context;
@ManyToOne
@JoinColumn(name = "ASSIGNMENT_ID")
private Assignment assignment;
@Column(name = "QUOTA_PERCENTAGE")
private Double quotaPercentage;
@Column(name = "ORDER_NUM")
private Integer orderNumber;
@Column(name = "NUM_ALLOC")
private Integer numberAllocated;
@Column(name = "NUM_UPLOADED")
private Integer numberUploaded;
@Type(type = "org.sakaiproject.springframework.orm.hibernate.type.InstantType")
@Column(name = "CREATED_DATE", nullable = false)
private Instant dateCreated;
@Type(type = "org.sakaiproject.springframework.orm.hibernate.type.InstantType")
@Column(name = "MODIFIED_DATE")
private Instant dateModified;
@Column(name = "MODIFIER", length = 99)
private String modifier;
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@OneToMany(mappedBy = "assignmentMarker", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private Set<AssignmentSubmissionMarker> submissionMarkers = new HashSet<>();
}