Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException when deactivating optimistic locking for domain classes with Hibernate 5.4.30.Final #1447

Closed
3 of 4 tasks
davidkron opened this issue Mar 25, 2021 · 2 comments

Comments

@davidkron
Copy link

I wanted to upgrade the Hibernate version to 5.4.30.Final in my application, but this caused a NullPointerException during startup of the application. The problem only happens when deactivating optimistic locking for specific domain classes like this:

static mapping = {
    version false
}

In a newly created grails-app this works, as the default Hibernate version used in the template is 5.4.18.Final.

The culprit seems to be the following code in hibernate-core:
https://github.com/hibernate/hibernate-orm/blob/dca2cabaf26fafb30baead8ba0e3d7229fb67c65/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java#L389-L390

In version 5.4.18 this was implemented like this:
https://github.com/hibernate/hibernate-orm/blob/ab9de8e428df4202ae9ed22787a5d90f2e87203a/hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java#L380-L383

As it seems from the Hibernate code, OptimisticLockStyle should not be null as it is an enumeration and this enumeration explicitely contains a constant NONE for the case where optimistic locking should be deactivated. It seems that GORM sets the optimistic lock style to null in case of a version false mapping, which in the end causes the statement optimisticLockStyle.isAllOrDirty() to fail with a NullPointerException.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. create new grails app
  2. create a domain class with version false mapping
  3. update hibernate-core dependency in build.gradle to version org.hibernate:hibernate-core:5.4.30.Final
  4. start application

Expected Behaviour

It should work.

Actual Behaviour

Application fails to start up with the following exception:

Caused by: java.lang.NullPointerException: null
        at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:390)
        at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:609)
        at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:128)
        at sun.reflect.GeneratedConstructorAccessor69.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:96)
        ... 53 common frames omitted

Environment Information

  • Operating System: Windows 10
  • GORM Version: 7.0.8
  • Grails Version (if using Grails): 4.0.9
  • JDK Version: 11
@aulea
Copy link
Contributor

aulea commented Mar 25, 2021

Duplicate of grails/gorm-hibernate5#265

@davidkron
Copy link
Author

Sorry for the duplicate. I will close this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants