-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to implement oracle funtion to_number via cast
PostPosted: Mon Jun 20, 2005 2:30 am 
Newbie

Joined: Mon Jun 20, 2005 2:20 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.5
Mapping documents:
3.0
Code between sessionFactory.openSession() and session.close():
String query = "select cast(ord.orderNo as integer) as cst_number from Order ord";
int result = ((Integer)(session.createQuery(query).iterate().next())).intValue();

System.out.println("result="+result);
Full stack trace of any exception that occurs:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.MethodNode
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'cast' {originalText=cast}
\-[EXPR_LIST] SqlNode: 'exprList'
+-[DOT] DotNode: 'order0_.ORDER_NO' {propertyName=orderNo,dereferenceType=4,propertyPath=orderNo,path=ord.orderNo,tableAlias=order0_,className=com.bsteel.baobao.eb.order.model.Order,classAlias=ord}
| +-[ALIAS_REF] IdentNode: 'order0_.ID' {alias=ord, className=com.test.model.Order, tableAlias=order0_}
| \-[IDENT] IdentNode: 'orderNo' {originalText=orderNo}
\-[IDENT] IdentNode: 'integer' {originalText=integer}

at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:136)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:440)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:351)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.java:126)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:471)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.iterate(SessionImpl.java:920)
at org.hibernate.impl.QueryImpl.iterate(QueryImpl.java:41)
at com.bsteel.baobao.eb.product.dao.impl.ProductOnlineDaoImplSt$1.doInHibernate(ProductOnlineDaoImplSt.java:72)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:311)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:292)
at com.bsteel.baobao.eb.product.dao.impl.ProductOnlineDaoImplSt.queryByProductNo(ProductOnlineDaoImplSt.java:68)
at com.bsteel.baobao.eb.product.dao.ProductOnlineDaoImplTest.testSave(ProductOnlineDaoImplTest.java:45)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)

Name and version of the database you are using:
oracle 9i
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

My Issue:
I trace the org.hibernate.dialect.function.CastFunction
I got it
public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
//TODO: pass in the arguments here...
return null; //it needs to be the argument type
}

this return value cause the " No data type for node" exception.
When this feature will be implemented?
How can I use HQL function to implement ORACLE to_number?


Top
 Profile  
 
 Post subject: Cast Function not implemented
PostPosted: Fri Jun 24, 2005 6:46 am 
Newbie

Joined: Mon May 24, 2004 8:34 am
Posts: 5
I too have found the same thing, where it appears that the cast function hasn't been implemented, even though in the documentation it indicates that it should be working.

This is quite frustrating, especially when trying to cast integers to floats in order to achieve a non-rounded figure when averaging a column.

Any idea when this is to be implemented? Or should I be writing my own implementation for the DB2 dialect which I am using. A little messy, but possible.

Regards

Matt


Top
 Profile  
 
 Post subject: Resolved for DB2. But a little messy
PostPosted: Fri Jun 24, 2005 7:47 am 
Newbie

Joined: Mon May 24, 2004 8:34 am
Posts: 5
I fixed this in my implementation. I am using hibernate 3.0.5 with DB2v7 Fixpack 8.

I had to get the source code from hibernate. I then copied the DB2Dialect class into my own application and altered one line of this, by adding the following to the constructor:
registerFunction( "cast", new DB2CastFunction() );

Then, as you can see by the above line of code, I wrote my own cast class, which implements SQLFunction, so that the method getReturnType returned what it was supposed to.

Finally, I altered my hibernate.cfg.xml file to use the new dialect:
<property name="dialect">my.own.package.DB2Dialect</property>

And everything seemed to work fine from there.

Hope this helps anyone else wanting to do any casting until this feature is included in the production version of hibernate.

Regards

Matt Gaunt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 10:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
At present, CAST() is only working when used in the where clause. There is an existing issue that asks for a fix to this:

http://opensource.atlassian.com/project ... se/HHH-592

Patches are, of course, very welcome.


Top
 Profile  
 
 Post subject: thanks
PostPosted: Tue Jun 28, 2005 11:49 pm 
Newbie

Joined: Mon Jun 20, 2005 2:20 am
Posts: 2
I think that alternative solution is to extend that dialet and regiest another cast funtion before new version release.

thanks all.


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