-->
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: Criteria type safety problem (related to formula?)
PostPosted: Wed Jan 04, 2006 9:08 pm 
Newbie

Joined: Wed Mar 23, 2005 1:02 pm
Posts: 4
Hibernate version:
3.1 (no RC)

Relevant portion of mapping document:
<property
name="flight_level"
formula="fltLvl * 100"
type="java.lang.Integer"
column="fltLvl"
not-null="true"
length="5" >

<meta attribute="field-description">
@hibernate.property
column="fltLvl"
length="5"
not-null="true"
</meta>
</property>

Code between sessionFactory.openSession() and session.close():
Code:
Criteria crit = session.createCriteria( MyClass.class );
Criterion between = Expression.between( "flight_level", new Long( 40000 ), new Long( 50000 ) );
crit.add( between );
List list = crit.list();

Full stack trace of any exception that occurs:
org.hibernate.exception.SQLGrammarException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.doList(Loader.java:2153)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1492)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
at Test.test(Test.java:0)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
Caused by: java.sql.SQLException: No value specified for parameter 1
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1257)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:1205)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:969)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
... 24 more

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

The generated SQL (show_sql=true):
None. This fails before SQL is generated.


Is this expected behavior? If I substitute new Integer() for my new Long() code, this code works just fine. With Longs, it fails. The HQL version works fine:

Code:
String hql = "from MyClass where flight_level between "+40000L+" and "+50000L;
Query q = session.createQuery( hql );
List list = q.list();


This doesn't strike me as expected behavior. Am I missing something?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 05, 2006 4:31 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

How about this?
Criteria crit = session.createCriteria( MyClass.class );
crit.add(Expression.between( "flight_level", new Integer(40000), new Integer(50000) ));
List list = crit.list();

Since you have java.lang.Integer as the type for variable flight_level, you have use Integer else you should get a classcastException.

Did that help?

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


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.