I am migrating to Hibernate 3.1 and getting a NPE when doing a simple query (a Find All, with no where clause). I've traced the problem in the source and see that the issue is a null connection, which in turn comes from a connectionManager.getConnection() call. My question is why would this ever throw a NPE, and how can I debug the situation (hopefully without becoming a hibernate developer myself ;-> ).
The problem seems specific to our "User" object -- I can query other objects.
Hibernate version: 3.1
Full stack trace of any exception that occurs:
Code:
[exec] 15:36:18,661 ERROR [UserHelper] java.lang.NullPointerException
[exec] java.lang.NullPointerException
[exec] at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
[exec] at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
[exec] at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
[exec] at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
[exec] at org.hibernate.loader.Loader.doQuery(Loader.java:661)
[exec] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
[exec] at org.hibernate.loader.Loader.doList(Loader.java:2150)
[exec] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
[exec] at org.hibernate.loader.Loader.list(Loader.java:2024)
[exec] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
[exec] at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
[exec] at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146)
[exec] at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
[exec] at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
Name and version of the database you are using: MySQL 4The generated SQL (show_sql=true): Code:
[exec] 15:36:16,927 INFO [STDOUT] LoginBean.ejbCreate()
[exec] 15:36:17,896 INFO [STDOUT] Hibernate: select user0_.user_guid as user1_94_, user0_.UserID as UserI
D94_, user0_.Password as Password94_, user0_.UserName as UserName94_, user0_.isActive as isActive94_, user0_.D
ataEntryDate as DataEntr6_94_, user0_.DataEnterer as DataEnte7_94_ from user user0_ where user0_.UserID='imsma
' and user0_.Password='5f4dcc3b5aa765d61d8327deb882cf99'
[exec] 15:36:17,989 INFO [STDOUT] Hibernate: select roles0_.user_guid as user2_1_, roles0_.role_guid as r
ole1_1_, role1_.role_guid as role1_86_0_, role1_.Role as Role86_0_, role1_.DataEntryDate as DataEntr3_86_0_, r
ole1_.DataEnterer as DataEnte4_86_0_ from user_has_role roles0_ left outer join role role1_ on roles0_.role_gu
id=role1_.role_guid where roles0_.user_guid=?
[exec] 15:36:18,099 INFO [STDOUT] com.fgm.imsma.ejb.UserBean.ejbCreate()
[exec] 15:36:18,646 INFO [STDOUT] Hibernate: select user0_.user_guid as user1_94_, user0_.UserID as UserI
D94_, user0_.Password as Password94_, user0_.UserName as UserName94_, user0_.isActive as isActive94_, user0_.D
ataEntryDate as DataEntr6_94_, user0_.DataEnterer as DataEnte7_94_ from user user0_
I browsed the source (UTSL) and found that the null pointer exception is thrown here (I've removed a lot of irrelevant lines for brevity): Code:
class AbstractBatcher {
[...]
private PreparedStatement getPreparedStatement(
final Connection conn,
[... args removed ...] )
throws SQLException {
sql = getSQL( sql );
log(sql);
log.trace("preparing statement");
PreparedStatement result;
if (scrollable) {
[... code removed ...]
}
else {
if (callable) {
result = conn.prepareCall(sql);
}
else {
result = conn.prepareStatement(sql); <<<---- LINE 442
}
}
In turn, the offending null connection originates four stack frames up, in this method of AbstractBatcher: Code:
public PreparedStatement prepareQueryStatement(String sql, boolean scrollable, ScrollMode scrollMode)
throws SQLException, HibernateException {
logOpenPreparedStatement();
PreparedStatement ps = getPreparedStatement( connectionManager.getConnection(), sql, scrollable, scrollMode ); <<<--- LINE 105
So why would connectionManager.getConnection() not return a connection?
In our dev environment someone may have a bad mapping, but I'd expect that to show up as a SQL or Hibernate error rather than a NPE. Please help with any insights on the root cause or how to debug this.