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 in AbstractStringBasedJpaQuery.isJpaManaged() [DATAJPA-929] #1283

Closed
spring-projects-issues opened this issue Jul 18, 2016 · 13 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jul 18, 2016

Ondřej Havelka opened DATAJPA-929 and commented

Hi,
I'm using SpringData JPA Hopper-SR1 and I want to upgrade to Hopper-SR2 but I'm facing NullPointer exception in AbstractStringBasedJpaQuery.isJpaManaged() which in newly introduced in Hopper-SR2 (with Hopper-SR1 everything works fine)

I'm using Envers

I have entity DonwloadItem which has correspoding table "download_item"

@Entity
@Table(name = "download_item")
public class DownloadItem extends BaseVersionEntity {

    @Audited
    @NotNull
    @Size(max = DOWNLOAD_ITEM_NAME_LENGTH)
    @Column(nullable=false)
    private String name;

    ....
}

but in db there is also envers auditing table "download_item_AUD" which doesn't have corresponding Java Type and thats the problem

In method isJpaManaged() is called managedType.getJavaType() that returns null for ManagedType that contains DownloadItem_aud entity

Stacktrace:

java.lang.NullPointerException: null
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.isJpaManaged(AbstractStringBasedJpaQuery.java:155) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.createJpaQuery(AbstractStringBasedJpaQuery.java:141) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:80) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:176) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:114) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:102) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:92) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482) ~[spring-data-commons-1.12.2.RELEASE.jar:na]
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.12.2.RELEASE.jar:na]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.12.2.RELEASE.jar:na]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.2.RELEASE.jar:na]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
....

Affects: 1.10.2 (Hopper SR2)

Issue Links:

  • DATAJPA-904 Potential NullPointerException in JpaPersistentPropertyImpl.isEntity()

Referenced from: commits 0fae610, c4b9a03

Backported to: 1.10.3 (Hopper SR3)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 19, 2016

Oliver Drotbohm commented

Thanks for filing this, Ondřej. This looks very much related to (but not caused by) DATAJPA-904. Generally speaking, ManagedType is actually not allowed to ever return null from the calls to getJavaType(). Would you mind filing a ticket against Hibernate (Envers) to help avoiding this in the future? I'll be putting the necessary guards into place for now

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 19, 2016

Oliver Drotbohm commented

Nevermind, I already filed a ticket here

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jul 20, 2016

Chris Cranford commented

-Is this happening because the user is querying the Envers audit table through spring-data-jpa?-

Please disregard, I was looking at master rather than the explicit release related to this ticket

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Maximos Sapranidis commented

I am in the process of updating to Spring Boot 1.4 and just bumped into the exact same issue.
From hibernate side this seems to have been considered as closed, so is there any workaround or any plans for implementing one on spring side?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Chris Cranford commented

@Maximos - If you are using Hibernate 5.1 with Spring boot, set the version explicitly to 5.1.1.Final and it should be resolved. I believe Oliver may guard against this in his code as well moving forward

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Oliver Drotbohm commented

The fix for that has already been released in Ingalls M1, so you should be able to upgrade to that one by setting the spring-data-releasetrain.version property in your POM to Ingalls-M1

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 3, 2016

Maximos Sapranidis commented

Unfortunately both suggested solutions did not work for me, I guess I will have to wait for the official update :(

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 5, 2016

Oliver Drotbohm commented

What do you exactly mean with "didn't work for me"?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 5, 2016

Maximos Sapranidis commented

After I specify the hibernate version I manage to make most of my tests pass but for some integration tests I am getting from the repository the following exception:

java.lang.NullPointerException
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.isJpaManaged(AbstractStringBasedJpaQuery.java:155)
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.createJpaQuery(AbstractStringBasedJpaQuery.java:141)
	at org.springframework.data.jpa.repository.query.AbstractStringBasedJpaQuery.doCreateQuery(AbstractStringBasedJpaQuery.java:80)

The specific repository is handling one part of a many to many relation between users and accounts.
The user object has some fields annotated with @Audited, so I assume this could be related to this exception.

Another thing I have noticed, is that when running a test method then the test passes as expected, but when running the whole class then the test fails.

Hope this gave some more insights,

Cheers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 5, 2016

Oliver Drotbohm commented

While the issue is in fact caused by Hibernate the Spring Data JPA version I suggested to update to has a workaround for that bug. So if you follow the advice above you should be abe to use a version, that has this fixed

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 12, 2016

Maximos Sapranidis commented

The issue is indeed resolved using the latest release but now I just bumped into another issue, we are using Optional return type and JPQL projection to create an object (not an Entity type)
The error is :

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Optional<?>] to type [com.cookies.domain.dto.AuthenticationPrincipal]

The Query is :

@Repository
public interface UserPrincipalRepository extends CrudRepository<UserAccountPair, String> {

    @Query(value = "SELECT " +
            "new xxx.AuthenticationPrincipal(u.id, u.email, u.password, u.enabled) " +
            "FROM ApiUser u "
            + "WHERE LOWER(u.email) = LOWER(?1)")
    Optional<AuthenticationPrincipal> findUserForAuthentication(String string);
}

If I remove the Optional the query works as expected, but this was working as is in the previous versions.

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 12, 2016

Oliver Drotbohm commented

Would you mind opening another ticket for this, please?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 12, 2016

Maximos Sapranidis commented

Yes, definitely, here you go DATAJPA-951 thanks for the quick response

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

No branches or pull requests

2 participants