In previous versions of JBoss EAP 6, the use of scalars within a Query, when using the Hibernate query cache, was causing users to encounter a NullPointerException. An example of a query that would produce the exception is:
----
query.addScalar("emp_first_name");
----
The problem was caused by code that attempted to automatically identify the Hibernate Type needed to handle the scalar (StringType, for example). In this release the code has been modified to correctly identify the handler needed.
For releases prior to 6.3.0, explicitly defining the type within the query scalar will avoid the NPE:
----
query.addScalar("emp_first_name", new StringType());
----
NPE while running the following cached NamedNativeQuery with an scalar result:
{code}
@NamedNativeQuery(name = Member.COUNT_MEMBER_QUERY, query = "SELECT COUNT(*) AS mCount from MemberHibernate4Demo", cacheable = true, readOnly = true, resultSetMapping = "Member.countQuery.Mapping")
@SqlResultSetMapping(name = "Member.countQuery.Mapping", columns =
{ @ColumnResult(name = "mCount") })
{code}
He get the following NullPointerException:
{code}
11:16:59,929 INFO [org.jboss.as.quickstart.hibernate4.controller.MemberController] (http-/127.0.0.1:8080-1) namedQuery = SQLQueryImpl(SELECT COUNT(*) AS mCount from MemberHibernate4Demo)
11:16:59,939 INFO [stdout] (http-/127.0.0.1:8080-1) Hibernate: SELECT COUNT(*) AS mCount from MemberHibernate4Demo
11:16:59,949 SEVERE [org.jboss.as.quickstart.hibernate4.controller.MemberController] (http-/127.0.0.1:8080-1) FIXME: Error while executing namedQuery! : java.lang.NullPointerException
at org.hibernate.cache.internal.StandardQueryCache.put(StandardQueryCache.java:111) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2482) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2363) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.loader.Loader.list(Loader.java:2324) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1827) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:905) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1]
at org.jboss.as.quickstart.hibernate4.controller.MemberController.executeQuerySingleResult(MemberController.java:91) [classes:]
{code}
The issue does not occur if we disable the caching. Same as [1]
[1] https://hibernate.atlassian.net/browse/HHH-3051
Brett, can you please supply a draft release note that adheres to the preformatted points in the Doc Text field above?
I'm having trouble understanding the issue and its fix for the EAP 6.3.0 release notes document.
I can't seem to get my changes to the Doc Text field to stick after a save of this ticket so I'm posting them here.
The elements required for an adequate release note are:
Cause:
Consequence:
Fix:
Result:
NPE while running the following cached NamedNativeQuery with an scalar result: {code} @NamedNativeQuery(name = Member.COUNT_MEMBER_QUERY, query = "SELECT COUNT(*) AS mCount from MemberHibernate4Demo", cacheable = true, readOnly = true, resultSetMapping = "Member.countQuery.Mapping") @SqlResultSetMapping(name = "Member.countQuery.Mapping", columns = { @ColumnResult(name = "mCount") }) {code} He get the following NullPointerException: {code} 11:16:59,929 INFO [org.jboss.as.quickstart.hibernate4.controller.MemberController] (http-/127.0.0.1:8080-1) namedQuery = SQLQueryImpl(SELECT COUNT(*) AS mCount from MemberHibernate4Demo) 11:16:59,939 INFO [stdout] (http-/127.0.0.1:8080-1) Hibernate: SELECT COUNT(*) AS mCount from MemberHibernate4Demo 11:16:59,949 SEVERE [org.jboss.as.quickstart.hibernate4.controller.MemberController] (http-/127.0.0.1:8080-1) FIXME: Error while executing namedQuery! : java.lang.NullPointerException at org.hibernate.cache.internal.StandardQueryCache.put(StandardQueryCache.java:111) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2482) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2363) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.loader.Loader.list(Loader.java:2324) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1827) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:231) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:157) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.hibernate.internal.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:905) [hibernate-core-4.2.0.SP1-redhat-1.jar:4.2.0.SP1-redhat-1] at org.jboss.as.quickstart.hibernate4.controller.MemberController.executeQuerySingleResult(MemberController.java:91) [classes:] {code} The issue does not occur if we disable the caching. Same as [1] [1] https://hibernate.atlassian.net/browse/HHH-3051