-->
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: Can I include a Java function in an hql query?
PostPosted: Thu Apr 05, 2007 12:18 am 
Newbie

Joined: Fri Jan 12, 2007 7:13 pm
Posts: 4
Bear with me... This isn't as odd as it sounds...

I want to write an hql query like this:

"from Person p where p.name='Smith' and p.age > 20"

where 'name' is a standard Hibernate mapped and persisted field but 'age' is programmatically generated.

It looks like I need to map the 'age' field in my hbm mapping in order to include it in my hql query. The problem is that the implementation of the age method doesn't get its value directly from a database column and it isn't persisted in the database. It's a calculation I do in my Java code. (I don't think it is a 'generated' field in the normal sense of a database generated field).

Is there a way to tell Hibernate that the field 'age' is programmtically generated in Java code and not by the database?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 12:58 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi pfarwell,

use formula in HBM for age and you could able to do same thing in HQL

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 7:55 am 
Newbie

Joined: Fri Jan 12, 2007 7:13 pm
Posts: 4
Thanks for the advice.

I considered using the formula feature, but my understanding is that formulas are themselves hql (or hql fragments) that run against the database. I'm looking for a way to call a java method (a getter), rather than invoking a db select. Is it possible to use formulas for something other than db selects?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 8:22 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi pfarwell,

then you need to handle it in business layer .Hibernate works on DB.

_________________
Dharmendra Pandey


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.