-->
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.  [ 7 posts ] 
Author Message
 Post subject: hibernate query problem or desired behavior ?
PostPosted: Wed Jan 25, 2006 6:17 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
It seems like a bug, I don't know. If the below code is changed to use

" AND msg.timestamp > ?" and
return session.createQuery(query).setLong(0,l).list()

it works.

Hibernate version: 3.1.1

Mapping documents: <property name="timestamp" type="long" column="TIMESTAMP" />

Code between sessionFactory.openSession() and session.close():

long l = (System.currentTimeMillis() - millsBeforeNow);
String query = "FROM LearningMessage msg WHERE msg.timestamp > "
+ l : "");
return session.createQuery(query).list();



Full stack trace of any exception that occurs:

java.lang.NumberFormatException: For input string: "1137183884835"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:459)
java.lang.Integer.valueOf(Integer.java:553)
org.hibernate.hql.ast.util.LiteralProcessor.processNumeric(LiteralProcessor.java:216)
org.hibernate.hql.ast.HqlSqlWalker.processNumericLiteral(HqlSqlWalker.java:757)
org.hibernate.hql.antlr.HqlSqlBaseWalker.literal(HqlSqlBaseWalker.java:2618)
org.hibernate.hql.antlr.HqlSqlBaseWalker.constant(HqlSqlBaseWalker.java:4416)
org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1262)
org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4032)
org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3593)
org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1758)
org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1686)
org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:105)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1600)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1178)
$Proxy48.createQuery(Unknown Source)
com.radarfind.dao.hibernate.HibernateRSSIImpl$4.doInHibernate(HibernateRSSIImpl.java:275)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:337)
com.radarfind.dao.hibernate.HibernateRSSIImpl.getLatestLearningMessages(HibernateRSSIImpl.java:263)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:335)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:181)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:148)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
$Proxy45.getLatestLearningMessages(Unknown Source)
com.radarfind.domain.managers.RSSIManager.getLearningMessages(RSSIManager.java:184)
com.radarfind.web.controllers.GenericListController.listLearningHome(GenericListController.java:154)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:369)
org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:325)
org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:717)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:658)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:347)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:174)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)



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

The generated SQL (show_sql=true): not displayed

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:42 am 
Newbie

Joined: Wed Dec 14, 2005 6:50 am
Posts: 17
May the sqls whould help to see what really is generated....
Quote:
The generated SQL (show_sql=true): not displayed


Top
 Profile  
 
 Post subject: Re: hibernate query problem or desired behavior ?
PostPosted: Wed Jan 25, 2006 11:58 am 
Newbie

Joined: Thu Oct 14, 2004 2:48 pm
Posts: 4
it should work:

java.util.Date d = new java.util.Date(System.currentTimeMillis() - millsBeforeNow);
query.setTimeStamp("l", d);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 3:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
you're trying to compare a timestamp (date/time) with a numeric value. try that in your database's query tool ;)

Typically JDBC drivers perform data conversions on PreparedStatement parameter bind values to coerce them to an expected type (if possible). Obviously a long *can* be coerced to a date/time...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 6:49 am 
Beginner
Beginner

Joined: Thu Jun 10, 2004 6:52 am
Posts: 29
steve wrote:
you're trying to compare a timestamp (date/time) with a numeric value


Well, the name is actually missleading. the property name is timestamp, it's type is long. I think it shouldn't be parsed into an integer.

UPDATE: I've just tested with Hibernate 3.1 and it works fine. So the porblem occurs in Hibernate 3.1.1


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well, '1137183884835' is too large for an integer value. Use '1137183884835L' (note the trailing 'L') instead


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 01, 2006 9:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Also, for something like you you should really consider using parameters for performance reasons...


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