-->
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.  [ 6 posts ] 
Author Message
 Post subject: Formula in Scalar Query (not in WHERE)
PostPosted: Wed Nov 19, 2003 10:46 pm 
Beginner
Beginner

Joined: Wed Nov 19, 2003 10:29 pm
Posts: 27
I realize there's an issue posted (HB-280) about using formula values in WHERE clauses, but this doesn't fall under that.

I have the following query:

select art.synopsis from News as art

synopsis is a foruma property.

I get:

QueryException: unresolved property:synposis

Now, if I load() the object instead of find(), I have no problem, and the formula works as it should.

I'm trying to implement a formulaic property that gives me only the first 40 characters of a field, so that when I show a listing of the rows, I don't have to have the complete content.

This is much, much more simple than trying to use a formula in a where clause, since the SQL generated for that portion of the select statement is identical to the SQL generated when the object is load()'ed.

If there's no way around this, could a hibernate developer point me at the likely area of code that would need modification to handle this?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 12:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah this is reasonable ... I wasn't quite aware that this doesn't work.

SelectParser has some calls to QueryTranslator.appendScalarSelectToken() and QueryTranslator.appendScalarSelectTokens(), thats a good place to start....


Top
 Profile  
 
 Post subject: Fixed, kinda...
PostPosted: Thu Nov 20, 2003 4:34 am 
Beginner
Beginner

Joined: Wed Nov 19, 2003 10:29 pm
Posts: 27
I'm not really sure how the best way to do this is. I'm not very familiar with Hibernate internals. Actually, haven't l needed to look at them until today. :)

In short, EntityPersister.toColumns (the version that takes a property name) is not able to look up the formula property using getPropertyColumnNames().

getPropertyColumnNames looks in the columnNamesByPropertyPath Hashtable that's from EntityPersister's superclass, AbstractEntityPersister.

Now, propertyColumnNames doesn't have the formula in it because EntityPersister only places properties in it f they AREN'T formulas.

So, the questions I have for you are:
Do you want to consider the formula a column name within EntityPersister?

Okay, what I've done, that works, is to alter keep track of which properties are formulas by adding a new closure list and putting the property names in for formulas. Then, when toColumns can't find the column, it looks through the list of formula properties again, finds it, and looks up the actual formula text from the closure.

It seems to work for now. I'm sure there's a much, much better way to do it, though. Do you want a patch, or do you want to do a more proper job yourself?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 20, 2003 4:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Umm submit the patch to JIRA, with a link to this description.

I'm sure I'll have to adjust the implementation, but having *something* tells me where to go.


Top
 Profile  
 
 Post subject: Has this been fixed in 2.1?
PostPosted: Wed Dec 17, 2003 2:31 am 
Beginner
Beginner

Joined: Wed Nov 19, 2003 10:29 pm
Posts: 27
I didn't get around to submitting the patch for this, but I noticed that the 2.1 supposedly fixes the problem of allowing a formula in the where clause. Does this also fix the problem of allowing a formula in a scalar select? I'm trying to decide if I should update to 2.1, or stick with my 2.0 version that's patched to fix this. If it hasn't been updated, I'll probably attempt to port the fix to 2.1, which is hopefully better structured in that area to handle this. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 2:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
yes, it is supported AFAIK.


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