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

Potential NullPointerException in JpaPersistentPropertyImpl.isEntity() [DATAJPA-904] #1259

Closed
spring-projects-issues opened this issue May 26, 2016 · 3 comments
Assignees
Labels
in: core type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented May 26, 2016

Daniel Durette opened DATAJPA-904 and commented

Hi,

I'm using Hibernate to map the tables of our database and some of them are audited with Envers (@Audited on the entity class). To solve the same problem that is described in DATAJPA-885, I switched to the latest snapshot (1.11.0).

I'm now getting a NullPointerException at the start of the application on the table_AUD classes generated by Hibernate. The NPE is because the javaType of the _AUD EmbeddableTypeImpl object is null.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is java.lang.NullPointerException
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
	at sgcib.ged.bcs.spring.SpringLauncher.launch(SpringLauncher.java:57)
	at sgcib.ged.bcs.spring.SpringLauncher.launch(SpringLauncher.java:38)
	at sgcib.ged.bcs.spring.SpringLauncher.launch(SpringLauncher.java:26)
	at sgcib.ged.bcs.reflex.server.ReflexServer.main(ReflexServer.java:13)
Caused by: java.lang.NullPointerException
	at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.isEntity(JpaPersistentPropertyImpl.java:161)
	at org.springframework.data.mapping.model.AbstractPersistentProperty.getPersistentEntityType(AbstractPersistentProperty.java:129)
	at org.springframework.data.jpa.mapping.JpaPersistentPropertyImpl.getPersistentEntityType(JpaPersistentPropertyImpl.java:133)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:488)
	at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:446)
	at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:689)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:314)
	at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:276)
	at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:392)
	at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:73)
	at org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
	at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
	... 15 more

How do I solve this problem? Is this a problem in Hibernate?


Affects: 1.9.4 (Gosling SR4), 1.10.1 (Hopper SR1)

Issue Links:

  • DATAJPA-929 NullPointerException in AbstractStringBasedJpaQuery.isJpaManaged()

Backported to: 1.10.2 (Hopper SR2), 1.9.5 (Gosling SR5)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 26, 2016

Oliver Drotbohm commented

I'd argue it is. ManagedType.getJavaType() is supposed to never return null. I am not sure how this would make any sense at all. I think we can still guard against that but I strongly suggest to file a ticket against Hibernate

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 21, 2017

Surya commented

hi Oliver,

I encountered this issue while upgrading our application from jdk 7 to jdk 8 and had to make the following adjustments:

FROM :
hibernate-core 4.3.10
hibernate-ehcache 4.3.10
hibernate-entitymanager 4.3.10
hibernate-jpa-2.1
spring-data-jpa 1.8.0
spring-data-commons - 1.10.0
spring-beans - 4.1.7
spring-core - 4.1.7
javassist 3.18.1-GA

TO :
hibernate-core 4.3.11
hibernate-ehcache 4.3.11
hibernate-entitymanager 4.3.11
hibernate-jpa-2.1
spring-data-jpa 1.8.0
spring-data-commons - 1.10.2
spring-beans - 4.1.7
spring-core - 4.1.7
javassist 3.20.0-GA

I read your comments @ https://hibernate.atlassian.net/browse/HHH-10968

Even though I got past this issue for the migration by researching on google, I do not understand the issue and its solution completely. Can you please explain to me in layman's terms what the issue is and how the version upgrades solves the issue ? Any time or explanation you can provide me will be greatly appreciated. Thank you for your time.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 24, 2017

Jens Schauder commented

From the Spring Data view of things: Hibernate broke a contract of an API JPA by returning {{null}. They felt that would be OK since it is used for things outside the scope of JPA.

Oliver argued, that if one provides an instance implementing an interface from some specification, that instance should behave like described in that specification. People from Hibernate seemed to disagree.

Anyway, the issue on the Hibernate side got fixed, so I assume the method in question doesn't return null anymore. Also Oliver added null} checks, so even if it does return {{null no NPE is thrown

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

No branches or pull requests

2 participants