Hibernate 樂觀鎖 version 欄位的型別不正確引起的異常
在持久化類中使用樂觀鎖optimistic-lock="version",
private String rec_Ver;
/**
* @hibernate.version column="REC_VER"
* @return
*/
public String getRec_Ver() {
return rec_Ver;
}
public void setRec_Ver(String rec_Ver) {
this.rec_Ver = rec_Ver;
}
<version
name="rec_Ver"
column="REC_VER"
type="java.lang.String"
/>
注意,上面的鎖型別是String,雖然編譯和啟動服務通過,但程式真正執行時會報錯:
%%%% Error Creating SessionFactory %%%%
java.lang.ClassCastException
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:689)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:690)
at net.sf.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:42)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:137)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:805)
at fwserver.utility.HibernateSessionFactory.initSessionMap(HibernateSessionFactory.java:124)
at fwserver.utility.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:91)
at fwserver.dao.hibernate.HibernateTemplate.getSession(HibernateTemplate.java:50)
at fwserver.dao.hibernate.HibernateTemplate.execute(HibernateTemplate.java:75)
at fwserver.dao.hibernate.HibernateTemplate.find(HibernateTemplate.java:368)
at fwserver.dao.hibernate.HibernateTemplate.find(HibernateTemplate.java:347)
at com.cosco.coris.bm.dao.UserAccountDAOHibernate.getBmLdapFlag(UserAccountDAOHibernate.java:81)
at com.cosco.coris.security.controller.SecurityLDAPAuthentication.authentication(SecurityLDAPAuthentication.java:39)
at com.cosco.coris.security.controller.SecurityController.dispatch(SecurityController.java:165)
at fwserver.controller.ControllerDispatcher.dispatchCorisRequestToCorisResponse(ControllerDispatcher.java:324)
at fwserver.controller.ControllerDispatcher.dispatch(ControllerDispatcher.java:185)
at fwserver.adapter.MainServlet.doGet(MainServlet.java:94)
at fwserver.adapter.MainServlet.doPost(MainServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
java.lang.NullPointerException
at fwserver.utility.HibernateSessionFactory.currentSession(HibernateSessionFactory.java:92)
at fwserver.dao.hibernate.HibernateTemplate.getSession(HibernateTemplate.java:50)
at fwserver.dao.hibernate.HibernateTemplate.execute(HibernateTemplate.java:75)
at fwserver.dao.hibernate.HibernateTemplate.find(HibernateTemplate.java:368)
at fwserver.dao.hibernate.HibernateTemplate.find(HibernateTemplate.java:347)
at com.cosco.coris.bm.dao.UserAccountDAOHibernate.getBmLdapFlag(UserAccountDAOHibernate.java:81)
at com.cosco.coris.security.controller.SecurityLDAPAuthentication.authentication(SecurityLDAPAuthentication.java:39)
at com.cosco.coris.security.controller.SecurityController.dispatch(SecurityController.java:165)
at fwserver.controller.ControllerDispatcher.dispatchCorisRequestToCorisResponse(ControllerDispatcher.java:324)
at fwserver.controller.ControllerDispatcher.dispatch(ControllerDispatcher.java:185)
at fwserver.adapter.MainServlet.doGet(MainServlet.java:94)
at fwserver.adapter.MainServlet.doPost(MainServlet.java:156)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
因提示的異常比較隱晦,所以較難發現,記錄希望有人能較快找到問題原因。