-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Bug when calling custom SQL query
PostPosted: Tue Dec 06, 2005 1:15 pm 
Newbie

Joined: Fri Nov 04, 2005 2:46 pm
Posts: 2
Java 1.5
Tomcat 5.5.9
libs from the Hibernate Source Zip of November 17, 2005

I have code which is calling:


Code:
System.out.println("coming in qry");
      strSQL = " SELECT count(T.ticket_id) as Hits, datepart(mm,T.created) as Mn, datepart(yyyy,T.created) as Yr ";
      strSQL += " FROM Tickets T  ";
      strSQL += " WHERE DateDiff(mm,T.created,getdate()) >= 0 AND DateDiff(mm,T.created,getdate()) < 12 ";
      strSQL += " group by datepart(mm,T.created), datepart(yyyy,T.created) ";
      strSQL += " order by Yr, Mn ";
     System.out.println("coming before session: " + strSQL);
     SQLQuery sql = getSession().createSQLQuery(strSQL);
     // help to understand the return types
     sql = sql.addScalar("Hits", Hibernate.INTEGER);
     sql = sql.addScalar("Mn",Hibernate.INTEGER);
     sql = sql.addScalar("Yr",Hibernate.INTEGER);
     System.out.println("-->" + sql.getQueryString());
     lst = sql.list();


So basically, I'm calling a custom SQL query from inside hibernate's session.

The error thrown was:

Code:
Exception caught: java.lang.Boolean
java.lang.ClassCastException: java.lang.Boolean
   at org.hibernate.type.StringType.toString(StringType.java:44)
   at org.hibernate.type.NullableType.toLoggableString(NullableType.java:169)
   at org.hibernate.pretty.Printer.toString(Printer.java:53)
   at org.hibernate.pretty.Printer.toString(Printer.java:90)
   at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:97)
   at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
   at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:881)
   at org.hibernate.impl.AbstractSessionImpl.getNativeSQLQueryPlan(AbstractSessionImpl.java:115)
   at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:121)
   at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:168)
   at com.duanemorris.bo.helptraxdeuce.dao.TicketsDAO.getTicketGraph(TicketsDAO.java:269)
   at com.duanemorris.bo.helptraxdeuce.dao.TicketsDAO.getTicketGraphCount(TicketsDAO.java:288)
   at com.duanemorris.ui.webapps.discovery.helptrax.Home.handleRequest(Home.java:124)
   at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doRequest(VelocityViewServlet.java:407)
   at org.apache.velocity.tools.view.servlet.VelocityViewServlet.doGet(VelocityViewServlet.java:373)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   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 jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
   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:856)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
   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)


I tracked the error down to this segment of code inside Hibernate by using the Stack Trace [AbstractFlushingEventListener.java:97]:

Code:
      //some statistics
      if ( log.isDebugEnabled() ) {
         log.debug( "Flushed: " +
               session.getActionQueue().numberOfInsertions() + " insertions, " +
               session.getActionQueue().numberOfUpdates() + " updates, " +
               session.getActionQueue().numberOfDeletions() + " deletions to " +
               persistenceContext.getEntityEntries().size() + " objects"
            );
         log.debug( "Flushed: " +
               session.getActionQueue().numberOfCollectionCreations() + " (re)creations, " +
               session.getActionQueue().numberOfCollectionUpdates() + " updates, " +
               session.getActionQueue().numberOfCollectionRemovals() + " removals to " +
               persistenceContext.getCollectionEntries().size() + " collections"
            );
         new Printer( session.getFactory() ).toString(
               persistenceContext.getEntitiesByKey().values().iterator(),
               session.getEntityMode()
            );
      }


So it seems that a boolean is being passed as a parameter when a string is to be expected.

To fix the problem, I changed our Log4J properties from DEBUG to a higher level.

If this is helpful to the developers or a fix has been provided already, I'd appreciate any feedback to this topic.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 06, 2005 6:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you have something mapped as a String but is actually Boolean.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:12 pm 
Newbie

Joined: Fri Nov 04, 2005 2:46 pm
Posts: 2
The problem was I was using a column of type char in the database.

In my hbm, I had it declared as a property which mapped to a String.

Since the database stored this column as either a 'Y' or a 'N', I created an IsXXX() method where XXX was the exact name of the property which did something like return getXXX.equalsIgnoreCase("Y").

I think somehow this made hibernate think that this property was a boolean and thus messed everything up.

Thanks for your reply.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.