-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NullPointerException when calling stored procedure
PostPosted: Sun Mar 18, 2007 4:45 pm 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
Hi,

I'm trying to call a very simple MySQL stored procedure that returns a very simple result set and I'm getting a NullPointerException.

Hibernate version:
3.2.1

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<sql-query name="mytestSP" callable="true">
<return-scalar column="permission_name" type="string"/>
{call my_proc()}
</sql-query>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
try {
HibernateUtil.getSessionFactory().getCurrentSession()
.beginTransaction();

Query query = HibernateUtil.getSessionFactory().getCurrentSession().getNamedQuery("mytestSP");
logger.info("QUERY_NULL=" + (query == null ? "YES" : "NO"));
query.list();
HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().commit();
} catch (Exception ex) {
ex.printStackTrace();
}

Hibernate debug level log and full stack trace of the exception that occurs:
22:28:50,220 INFO CmsServiceImpl:285 - QUERY_NULL=NO
22:28:50,221 DEBUG QueryPlanCache:118 - located native-sql query plan in cache ({call my_proc()})
22:28:50,222 DEBUG SessionImpl:1685 - SQL query: {call my_proc()}
22:28:50,233 DEBUG AbstractBatcher:358 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
22:28:50,233 DEBUG SQL:393 - {call my_proc()}
Hibernate: {call my_proc()}
22:28:50,234 DEBUG AbstractBatcher:476 - preparing statement
java.lang.NullPointerException
at com.mysql.jdbc.StringUtils.indexOfIgnoreCaseRespectQuotes(StringUtils.java:959)
at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1296)
at com.mysql.jdbc.DatabaseMetaData.getProcedureColumns(DatabaseMetaData.java:3670)
at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:702)
at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:513)
at com.mysql.jdbc.Connection.parseCallableStatement(Connection.java:4422)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4496)
at com.mysql.jdbc.Connection.prepareCall(Connection.java:4470)
at org.apache.commons.dbcp.DelegatingConnection.prepareCall(DelegatingConnection.java:212)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareCall(PoolingDataSource.java:268)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:494)
at org.hibernate.jdbc.AbstractBatcher.prepareCallableQueryStatement(AbstractBatcher.java:156)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1534)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2211)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2095)
at org.hibernate.loader.Loader.list(Loader.java:2090)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:150)
at com.vio.cms.server.CmsServiceImpl.getUser(CmsServiceImpl.java:286)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:281)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:167)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)

Name and version of the database you are using:
MySQL 5.0.30

The generated SQL (show_sql=true):
22:28:50,233 DEBUG SQL:393 - {call my_proc()}
Hibernate: {call my_proc()}

Stored procedure:
mysql> show create procedure my_proc;
+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------+
| Procedure | sql_mode | Create Procedure |
+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------+
| my_proc | | CREATE DEFINER=`myuser`@`my.ip.addr.ess` PROCEDURE `my_proc`()
DETERMINISTIC
BEGIN
select "TESTING" as permission_name;
END |
+-----------+----------+-------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> call my_proc;
+-----------------+
| permission_name |
+-----------------+
| TESTING |
+-----------------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Any hint as to why this NullPointerException occurs would be highly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 19, 2007 5:04 am 
Newbie

Joined: Sat Jan 20, 2007 10:29 am
Posts: 8
I omitted stating the version of the MySQL driver: it was MySQL® Connector/J 5.0.4.

And in the mean time I've found the cause of the NullPointerException. It is a bug in MySQL® Connector/J. I have upgraded the Connector/J to the last version (5.0.5) and no NullPointerException occurs. The procedure is now called correctly:

Code:
[java] Hibernate: {call my_proc()}
[java] 10:53:53,651 DEBUG StringType:122 - returning 'TESTING' as column: permission_name


So it was not a Hibernate issue, sorry for having opened this topic here.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.