-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with property & formula
PostPosted: Thu Apr 08, 2004 8:45 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
Hi,

I have this class
Code:
<class name="OrderHeader" table="REORDH">
...
<property name="statusDescription" formula="(select CLTEXT from RESCOL where CLLIST = 1005 AND CLVALN = 10)" />
</class>


i want to get the value of statusDescription from different table.

This is the sql hibernate is generating:
Code:
select
   orderheade0_.RHCUST= as RHCUST,
   orderheade0_.RHORNO as RHORNO,
   orderheade0_.RHCNSL as RHCNSL,
   orderheade0_.RHOSTS as RHOSTS,
   (select orderheade0_.CLTEXT from RESCOL where orderheade0_.CLLIST = 1005 AND orderheade0_.CLVALN = 10) as f0_
from REORDH orderheade0_
where (orderheade0_.RHCUST=? )


As you can see, the inner select is not what i expected.

I tried puuting alias but no change.

I tried to use other maped objects in the inner select but it didn't help as well.

what am i doing wrong?

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Formular is designed to provide a non-persistent property based on (usually only) existing fields. Here is a simple example:

<property name="sumval" formula="firstField + secondField" />

The formula is added to the select clause of the SQL to obtain the result. It is limited to what is valid as a expression within the select clause for the target database.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:07 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
excuse me but i think this is possible since i doing things like this, just add an alias, it shoud work

Code:
<class name="OrderHeader" table="REORDH">
...
<property name="statusDescription" formula="(select a.CLTEXT from RESCOL a where a.CLLIST = 1005 AND a.CLVALN = 10)" />
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I did say, if its valid in the select clause then its valid as the formula. Hibernate just passes it through to the database as straight SQL. I did not check the query closely - should have picked up the alias reference but I was not incorrect.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:22 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i did not say you were incorrect :))


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:24 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
:-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:30 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
excuse me but i think this is possible since i doing things like this, just add an alias, it shoud work

Code:
<class name="OrderHeader" table="REORDH">
...
<property name="statusDescription" formula="(select a.CLTEXT from RESCOL a where a.CLLIST = 1005 AND a.CLVALN = 10)" />
</class>


Yes it is working. Thank you so you are magician :-)

_________________
Oren Berenson


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
no no, Hibernate is Magic not me


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 08, 2004 9:36 am 
Beginner
Beginner

Joined: Wed Mar 03, 2004 6:38 am
Posts: 26
delpouve wrote:
no no, Hibernate is Magic not me


Ok :-)

_________________
Oren Berenson


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