下午好,
我不知道为什么这个查询会给出异常,有人可以帮我理解吗?
代码
SEVERE: Servlet.service() for servlet [jersey-servlet] in context with path [/returnitRest] threw exception [javax.persistence.TransactionRequiredException: Executing an update/delete query] with root cause
javax.persistence.TransactionRequiredException: Executing an update/delete query
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1492)
at returnitRest.EreturnResource.processEreturn(EreturnResource.java:954)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:76)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:148)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:191)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:200)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:103)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:493)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:415)
thank you very much
Excepion
private void add_Click(object sender, EventArgs e)
{
double g = 0;
// Controls.OfType will automatically find your DynaItems controls and cast them for you
foreach (DynaItems dynaItem in Controls.OfType<DynaItems>())
{
// Breakpoint here and check the value of dynaItem.price.Text
g += double.Parse(dynaItem.price.Text);
}
textBox1.Text = g.ToString();
}
答案 0 :(得分:0)
我的不好,我忘了开始交易。
这个解决方案:
@PUT
@Path("/process")
@Consumes(MediaType.APPLICATION_JSON)
public Response processEreturn(List<Long> ereturns){
EntityManager em = Utils.initEntityManager();
em.getTransaction().begin();
Query q = em.createQuery("UPDATE ereturn e SET e.processedByShipper = true WHERE e.id = 111713");
q.executeUpdate();
em.getTransaction().commit();
em.close();
return Response.ok().build();
}