-->
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.  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: does formula property have limitations?
PostPosted: Thu May 06, 2004 4:28 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I wonder if formula prop. have limitations about the number of the tables joined.

<class name= "A" table ="Area">
...
...
<property name = " latitude"
formula =" Select p.LATITUDE from Area a, Icao b, Place p where a.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID" />..


In Oracle this query works, but with hibernate, it gives errors.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:33 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
aaah sorry, I misjudged something
forget this post pls

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 4:44 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I think I did all well, but still I have a problem.
I cant join 3 tables (as the scenario above) within hibernate formula.
Am I doing something wrong?

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:33 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use parantheses formular="( select ... )" and check the SQL log output from Hibernate. Your database has to support subqueries.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 6:37 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
does Oracle supports sub-queries? I think it should

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 6:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
of course. just add parentheses


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 8:01 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I think I couldnt identify the problem. It is not easy to handle by just adding parantheses.

It is about the query that hibernate generates is not the one I want.

Let me identify the problem again: Here is the illustration:


class A : ID, status, latitude,longitude

table A : ID, STATUS, B_ID
table B: ID, NAME, C_ID
table C: ID, LATITUDE, LONGITUDE

mapping file:
<class name = "A" table = "A"..
<id...
<property
<property name = "latitude"
formula = "(Select c.LATITUDE from B b, C c, A a where
b.C_ID = c.ID and a.B_ID ="thisA". b.ID)" ....
</property>
</class>

Meanly, I want to hibernate to generate this query:

Select a1.ID , a1.STATUS, (select c.LATITUDE from C c, B b, A a2 where
a2.ID = a1.ID and a2.B_ID = b.ID and b.C_ID = c.ID) from A a1;


I need to have a instance of A in sub-select query, otherwise subquery will return a list. I mean I want to say hibernate that "return the latitude of C where C's id is equal to B's C_ID and the B's id is the A instance of the main query) 's B_ID , by that way I can ban the sub query to return list.

I should handle this by writing a query in my DAO class, but I want everything to be handled in the mapping file.

I hope that now the problem is clear.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 8:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about

<property name = " latitude"
formula =" Select p.LATITUDE from Icao b, Place p where ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID" />..


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 9:17 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
delpouve wrote:
what about

<property name = " latitude"
formula =" Select p.LATITUDE from Icao b, Place p where ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID" />..


This doesnt work.

It generates :

Select a_.ID as ID , (Select p.LATITUDE from ICAO b, a_.PLACE a_.p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_

and this query gives "Missing right paranthesis error"???

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 10:06 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
borak wrote:
delpouve wrote:
what about

<property name = " latitude"
formula =" Select p.LATITUDE from Icao b, Place p where ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID" />..


This doesnt work.

It generates :

Select a_.ID as ID , (Select p.LATITUDE from ICAO b, a_.PLACE a_.p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_

and this query gives "Missing right paranthesis error"???


The mistake is in the query that hibernate generates :

HibernateQuery: "Select a_.ID as ID , (Select p.LATITUDE from ICAO b, a_.PLACE a_.p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_ "

When I remove tha (a_.) from the PLACE p, it works!

ExpectedQuery: "Select a_.ID as ID , (Select p.LATITUDE from ICAO b,PLACE p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_ " Works Fine.

Hey hibernate team, why is going on while generate query?, why u add the (a_. before one of the tables)? What can I do to find a way of solution?
What am I doing wrong????
I know I must be missing something ...

_________________
-developer


Top
 Profile  
 
 Post subject: Is this a bug??
PostPosted: Thu May 06, 2004 10:17 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
I cant find the reason of that "idiot" query, I wonder if it is a bug

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 10:18 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Man, just learn to read! You have to use parantheses!

<property name="foo" formula="( select foo )"/>

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 10:25 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
<property name = " latitude"
formula ="( Select p.LATITUDE from Icao b, Place p where ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID )" />

cristian, that is the matter; I am using the parantheses if u mean the ones above. The idiot query still exists -)

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 10:40 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
borak wrote:
borak wrote:
delpouve wrote:
what about

<property name = " latitude"
formula =" (Select p.LATITUDE from Icao b, Place p where ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID)" />..


This doesnt work.

It generates :

Select a_.ID as ID , (Select p.LATITUDE from ICAO b, a_.PLACE a_.p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_

and this query gives "Missing right paranthesis error"???


The mistake is in the query that hibernate generates :

HibernateQuery: "Select a_.ID as ID , (Select p.LATITUDE from ICAO b, a_.PLACE a_.p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_ "

When I remove tha (a_.) from the PLACE p, it works!

ExpectedQuery: "Select a_.ID as ID , (Select p.LATITUDE from ICAO b,PLACE p where a_.ICAO_ID = b.ICAO_ID and b.PLACE_ID = p.PLACE_ID ) as f2_ from A a_ " Works Fine.

Hey hibernate team, why is going on while generate query?, why u add the (a_. before one of the tables)? What can I do to find a way of solution?
What am I doing wrong????
I know I must be missing something ...

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 10:51 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Is "Place" the name of the "outer" table? If yes, then don't specifiy it in the FROM clause of your subselect, but simply reference without an alias: "where b.PLACE_ID = PLACE_ID". Show us the full mapping for the class.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 27 posts ]  Go to page 1, 2  Next

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.