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.  [ 4 posts ] 
Author Message
 Post subject: Property formula expressions with bind variables
PostPosted: Wed May 26, 2004 8:51 pm 
Newbie

Joined: Thu Jan 29, 2004 2:51 pm
Posts: 9
Hibernate Version: 2.1.2
with Oracle 9i

I added a computed formula to one of my mappings that REQUIRES a bind variable:

Code:
      <property
         name="formulatedMessage"
         type="java.lang.String"
         update="true"
         insert="true"
         formula="decode(id,?,'Yes','No')"
         />

      <id
         name="id"
         column="id"
         type="java.lang.Long"
         unsaved-value="none">
           <generator class="assigned">
         </generator>
      </id>


and I want to execute an HQL query where I can pass in a value for that bind variable. It looks like

Code:
      String query = "from " + BlobTestBean.class.getName();
      Query hqlQuery = sess.createQuery(query);
      hqlQuery.setParameter(0, new Integer(1), Hibernate.INTEGER);
      List resultSet = hqlQuery.list();


When I run the code snippet above, I get an exception

Code:
java.lang.IllegalArgumentException: No positional parameters in query: from com.qrs.itm.dao.BlobTestBean
   at net.sf.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:137)
   at com.qrs.itm.dao.BlobTest.testRetrieveFormulatedValue(BlobTest.java:157)
...


and when I run the test above and comment out the line where the positional parameter is set, I get an exception from Oracle:

Code:
java.sql.SQLException: ORA-01008: not all variables bound

   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
   at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
...


Does Hibernate support a feature like this? Are there newer versions of Hibernate that do?

FYI, I'm happy with the SQL being produced which is:

Code:
2004-05-26 17:51:00,315 [main] DEBUG net.sf.hibernate.hql.QueryTranslator  - HQL: from com.qrs.itm.dao.BlobTestBean
2004-05-26 17:51:00,315 [main] DEBUG net.sf.hibernate.hql.QueryTranslator  - SQL: select blobtestbe0_.id as id, blobtestbe0_.msg as msg, blobtestbe0_.bytes as bytes, decode(blobtestbe0_.id,?,'Yes','No') as f0_ from BlobTest blobtestbe0_
2004-05-26 17:51:00,331 [main] DEBUG net.sf.hibernate.SQL  - select blobtestbe0_.id as id, blobtestbe0_.msg as msg, blobtestbe0_.bytes as bytes, decode(blobtestbe0_.id,?,'Yes','No') as f0_ from BlobTest blobtestbe0_


Thanks, Steve


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 11:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
sorry, this is not possible at this stage


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 27, 2004 1:44 am 
Newbie

Joined: Thu Jan 29, 2004 2:51 pm
Posts: 9
Any ideas how I could make this work?

Can one modify the O/R mapping at runtime? Maybe I could keep the computed formula property off the hbm.xml file when my application starts, and add it to the persister class at runtime.

Basically since I can't use bind variables in a computed formula I need to generate the SQL statement bit at runtime, i.e.

First query...
decode(id, 1, 'Yes', 'No')

Second query...
decode(id, 2, 'Yes', 'No')

Third Query...
decode(id, 3, 'Yes', 'No')

I hope this is possible!


Top
 Profile  
 
 Post subject: Will this be supported in a future version of hibernate?
PostPosted: Mon Feb 07, 2005 12:09 am 
Newbie

Joined: Mon Jan 24, 2005 11:48 pm
Posts: 5
Location: Newcastle, Australia
Is there any update on whether this will be supported in the future?


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