Java.lang.NullPointerException at Org.hibernate.type.LongType.next (Longtype.java

Source: Internet
Author: User

1, in order to solve the problems caused by concurrency, we usually declare a version management field on the entity class, and introduce the @version annotation, which simply realizes the optimistic locking function;

Java code
    1. @Version
    2. Private Long version;

2, when the Action form submission, Hibernate will be based on the type of operation (if it is new, the default is to generate a version 0 version number,

Each subsequent modification will be based on the existing version plus 1) to maintain the version number.

Application Scenarios:

If two people (A, b) at the same time to the same entity to make changes, a first submitted, b after the submission, then B will report the error. (Because A has been modified, the version number submitted by B is lower than the version number in the database and therefore cannot be updated).

Precautions:

Use the versioning field to be aware that the version number is to be committed when modified, or hibernate throws a null pointer exception because the current version cannot be referenced due to maintenance of the version number.

Hibernate exception Throw Location:

Java code
    1. Org.hibernate.type.LongType
    2. @SuppressWarnings ({ "unnecessaryboxing", "Unnecessaryunboxing"})
    3. Public long Next (long, Sessionimplementor session) {
    4. return long.valueof (Current.longvalue () + 1);
    5. }

Exception information:

Critical: 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)

Java.lang.NullPointerException at Org.hibernate.type.LongType.next (Longtype.java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.