yannbriancon / spring-hibernate-query-utils

Library giving tools to detect N+1 queries and count the queries generated with Spring and Hibernate
MIT License
135 stars 15 forks source link

NPE in HibernateQueryInterceptor #7

Closed Athou closed 4 years ago

Athou commented 4 years ago

Hey,

This lib looks great, I wanted to try it in my Spring Boot app (https://github.com/Athou/lapinstance) but I get a NullPointerException:

Caused by: java.lang.NullPointerException: null
    at com.yannbriancon.interceptor.HibernateQueryInterceptor.getEntity(HibernateQueryInterceptor.java:86) ~[spring-hibernate-query-utils-1.0.0.jar:1.0.0]
    at org.hibernate.internal.SessionImpl.getEntityUsingInterceptor(SessionImpl.java:550) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.getRow(Loader.java:1601) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:745) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.processResultSet(Loader.java:1008) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:964) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2815) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2797) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2629) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2624) ~[hibernate-core-5.4.10.Final.jar:5.4.10.Final]
...

Any idea ?

Thanks !

yannbriancon commented 4 years ago

Hello,

I think SessionImpl is using the default constructor and so does not initialize threadPreviouslyLoadedEntities.

I will take a look and keep you posted!

yannbriancon commented 4 years ago

@Athou Could you tell me when this happens and give me a configuration to debug?

I cloned your repo and run the app but there was no error.

Athou commented 4 years ago

I changed the app so that it can start without Discord integration. You should be able to just clone the repo and start the app without touching any configuration file, access http://localhost:8760/raids and get the NPE.

yannbriancon commented 4 years ago

A new bug fix has been released, change the version to 1.0.1 and it should work ;)

Athou commented 4 years ago

Yes it's now working as expected, thanks!