Id が 1 つしかない非常に単純な POJO があり、保存と更新が正常に機能しているレコードを削除すると、例外が発生します。commit() を使用しない場合、例外は発生しませんが、使用すると例外が発生します。これがコードです...
public class DeleteCompanyRecords {
public static boolean deleteCompany(String comname){
Boolean res=false;
Session session = null;
String comid=GenCompanyCodeWhenGivenCompanyName.genCompanyCode(comname);
System.out.println(comid);
Transaction tx = null;
try{
session = SessionCreate.getSessionFactory().openSession();
tx=(Transaction) session.getTransaction();
ElitSysCompanyMaster employee =
(ElitSysCompanyMaster)session.get(ElitSysCompanyMaster.class, comid);
session.delete(employee);res=true;
session.flush();//tx.commit() also gives exception here.
}catch (Exception e) {
session.getTransaction().rollback();
e.printStackTrace();
res=false;
} finally {
if (session != null)
if (session.isOpen()){
session.close();}
}
return res;
}
上記のコードでは、tx.commit を使用すると、同じ例外と if(wasCommitted()) ステートメントもスローされます。ガイドしてください。この完全なプロジェクトのために働いているのは私だけです。他に誰もいません。
このテーブルは非常に単純なテーブルで、現時点ではマッピングはありません。例外はそのままです。
SEVERE: Servlet.service() for servlet [jsp] in context with path [/SecurePass] threw exception [org.hibernate.TransactionException: Transaction not successfully started] with root cause
org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:202)
at classes.deleteclasses.DeleteCompanyRecords.deleteCompany(DeleteCompanyRecords.java:25)
at org.apache.jsp.DeleteRecords.DeleteCompany_jsp._jspService(DeleteCompany_jsp.java:81)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)