java.lang.NullPointerException at org.hibernate.type.LongType.next(LongType.java

1、为了初步解决并发造成的问题,我们通常会在实体类上声明一个版本管理字段,并且引入的@version注解,这就就简单实现了乐观锁功能;

Java代码  

  1. @Version
  2. private Long    version;

2、在操作表单提交时,hibernate会根据操作类型进行(如果是新增,默认会生成一个版本为0的版本号,

后面每次修改都会在现有版本后的基础上加1)对版本号进行维护。

应用场景:

如果两个人(甲,乙)同时对同实体进行修改,甲先提交,乙后提交,那么乙提交是会报错的。(因为甲已修改,乙提交的版本号比数据库中的版本号低,因此不能进行更新)。

注意事项:

运用版本控制字段需要注意,在修改时要将版本号一起提交,否则hibernate因为维护版本号时因无法参考当前版本而抛出空指针异常。

hibernate异常抛出位置:

Java代码  

  1. org.hibernate.type.LongType
  2. @SuppressWarnings({ "UnnecessaryBoxing", "UnnecessaryUnboxing" })
  3. public Long next(Long current, SessionImplementor session) {
  4. return Long.valueOf( current.longValue() + 1 );
  5. }

异常信息:

严重: Servlet.service() for servlet springmvc threw exception

java.lang.NullPointerException

at org.hibernate.type.LongType.next(LongType.java:76)

at org.hibernate.type.LongType.next(LongType.java:40)

at org.hibernate.engine.Versioning.increment(Versioning.java:131)

at org.hibernate.event.def.DefaultFlushEntityEventListener.getNextVersion(DefaultFlushEntityEventListener.java:406)

at org.hibernate.event.def.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:296)

at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:155)

at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)

at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)

at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)

原文地址:https://www.cnblogs.com/renjiaqi/p/9027820.html

时间: 2024-11-13 06:40:55

java.lang.NullPointerException at org.hibernate.type.LongType.next(LongType.java的相关文章

java.lang.NullPointerException at com.pp.controller.PPUserController.updateDetail(PPUserController.java:34)

问题原因:忘记写@Resource: 由此而知:可能是service没有引进去. 全部错误代码: 22:33:17,883 DEBUG SessionImpl:243 - Opened session at timestamp: 14308363978 22:34:11,470 ERROR AdminController:39 - 用户User [id=11, name=caowenyan, pwd=null, mail=null, photo=null, createdate=null, lo

java.lang.NullPointerException at org.apache.jsp.**_jsp.jspInit(**_jsp.java)tomcat启动异常解决方法

今天遇到的其他一个问题就是,启动tomcat时,报:java.lang.NullPointerException at org.apache.jsp.**_jsp.jspInit(index_jsp.java)异常,因为我刚刚配置服务器,以为JSP页面出现了问题,不过写了一个空的JSP页面依旧是,后来才知道,jar包冲突导致的,我在tomcat的lib目录下放了jsp-api.jar的jar包,而项目中最初也一直有一个这个jar包,方法产生了冲突.解决办法就是删除掉项目里WEB-INF/lib下

?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException

使用BoneCP作为连接池,在启动Tomcat报出以下异常: 一月 02, 2016 2:12:17 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:mynewdpi' did not find a

HTTP Status 500 - Request processing failed; nested exception is java.lang.NullPointerException

type Exception report message Request processing failed; nested exception is java.lang.NullPointerException description The server encountered an internal error that prevented it from fulfilling this request. exception org.springframework.web.util.Ne

web 环境项目(intellj部署的tomcat) 重启时报 Exception in thread "HouseKeeper" java.lang.NullPointerException (转)

Exception in thread "HouseKeeper" java.lang.NullPointerException at org.logicalcobwebs.proxool.HouseKeeperController.getHouseKeeperToRun(HouseKeeperController.java:52) at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:33

solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

问题描述 报如下错误,很显然,问题原因:空指针异常: ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties Error loading DataImportScheduler propertiesjava.lang.NullPointerException        at sun.nio.fs.UnixPath.normalizeAndCheck(UnixPath.java:77)        at

解决tomcat6部署spring4+mybatisJSP页面产生的500错误,控制台报java.lang.NullPointerException的问题

搭建spring4+mybatis+springMVC访问项目时产生异常: 严重: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException at org.apache.jsp.index_jsp._jspInit(index_jsp.java:22) at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:52) at o

Servlet.service() for servlet UserServlet threw exception java.lang.NullPointerException 空指针异常

错误付现: 严重: Servlet.service() for servlet UserServlet threw exceptionjava.lang.NullPointerException at com.liuyang.servlet.UserServlet.doGet(UserServlet.java:17) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.Http

报错!!!Servlet.service() for servlet [action] in context with path [/myssh] threw exception [java.lang.NullPointerException] with root cause java.lang.NullPointerException

这个为什么报错啊~~ at com.hsp.basic.BasicService.executeQuery(BasicService.java:33) 这个对应的语句是   Query query =this.sessionFactory.getCurrentSession().createQuery(hql); Sep 24, 2017 11:39:50 PM org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.se