-->
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.  [ 11 posts ] 
Author Message
 Post subject: "value types" (composite-elements) in HQL from cla
PostPosted: Thu Aug 28, 2003 2:19 am 
Newbie

Joined: Wed Aug 27, 2003 3:09 am
Posts: 17
Hi,

I have a set of objects which have the classical "many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys)" relationships.

http://hibernate.org/118.html#A10

By using composite-element, tables are correctly created.

From the road map, it says: "support for collections of "value" type in HQL from clause (DONE)
-so we can query composite-elements
-so we can FETCH collections of value type"

I also have the latest beta of Hibernate on hand, but it doesn't contains any query examples.

My problem is how to retrieve the parent objects by specifiying the property value of composite-elements?

THanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 2:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The only reason there are no specific examples is 'cos the syntax is unified with the syntax for collections of entities!

from Foo foo
join foo.links link
where link.property = :linkProperty

where foo.links is a collection of composite elements


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 2:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Since I'm proud of this new feature, heres another example ;)


Code:
select foo, bar
from Foo foo
join foo.links link
join link.bar bar
where link.property = :linkProperty



returns the related Foo + Bar ordered pairs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 28, 2003 4:00 am 
Newbie

Joined: Wed Aug 27, 2003 3:09 am
Posts: 17
GREAT!

This feature is simply "COOL".

Thank you!

_________________
Hibernate is successful.

Not only because of its code quality, but it is deal to the support from the nice Hibernate Team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 2:17 pm 
Newbie

Joined: Thu Oct 16, 2003 7:22 pm
Posts: 12
I have a variation of this question...

I noticed that I can not do:

Quote:
select link, bar
from Foo foo
join foo.links link
join link.bar bar
where link.property = :linkProperty


instead, I have to do:

Quote:
select elements(foo.links), bar
from Foo foo
join foo.links link
join link.bar bar
where link.property = :linkProperty


which is fine, until I try to do:

Quote:
select elements(foo.links), bar
from Foo foo
join foo.links link
join link.bar bar
where link.property = :linkProperty
ORDER BY link.property2


which fails... basically I want to find all the associated objects of Foo ordered by a property from the composite element table. How can this be done?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 4:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ummmm interesting ... does this work:


Code:
select foo, bar
from Foo foo
  join foo.links link
  join link.bar bar
where link.property = :linkProperty
order by link.property2


may not be exactly what you want, but I'd like to know that it works...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 5:40 pm 
Newbie

Joined: Thu Oct 16, 2003 7:22 pm
Posts: 12
gavin, before anything, i just want to thanks for all your effort on Hibernate. The quality of the product and the level of support is really unsurpassed by anything i've ever seen.

back to your question: yes, that does work.

however, the desired result is to get the link information along with the associated bar entity object.

i.e.
Quote:
SELECT link, bar FROM ...

or even
Quote:
SELECT link FROM ...

since bar is already a property of link.

The error that occurs is:

Code:
net.sf.hibernate.QueryException: could not resolve property: id
        at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:33)
        at net.sf.hibernate.collection.CollectionPersister.toType(CollectionPersister.java:943)
        at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:242)
        at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:281)
        at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:14)
        ...


Also, looks like AbstractPropertyMapping.java has been deleted from cvs since the release 2.1b4...?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 6:00 pm 
Newbie

Joined: Thu Oct 16, 2003 7:22 pm
Posts: 12
Update...

It looks like if I change the query to:

Quote:
SELECT link.property, bar FROM ...


It'll work. So the problem seems to be related to the fact that path expressions can not end on a component types (i guess elements of a composite-element are components)

Also, i forget to mention, the reason why i am even down this road in the 1st place is because I can not use Session.Filter() to filter (i.e. sort by) collections of composite elements.

daniel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 8:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Also, i forget to mention, the reason why i am even down this road in the 1st place is because I can not use Session.Filter() to filter (i.e. sort by) collections of composite elements


Yeah, this is on my TODO list. Its nowhere near the top, however :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 21, 2003 10:02 pm 
Newbie

Joined: Thu Oct 16, 2003 7:22 pm
Posts: 12
Ok, I figured out a hack for this...

Code:
SELECT new Link(link.property1, link.property2, link.property3, bar)
FROM Foo foo
JOIN foo.links link
JOIN link.bar bar
WHERE link.property = :linkProperty
ORDER BY link.property2 ASC AND bar.property1 DESC


And make sure the corresponding constructor is available on Link... phew...

gavin, as far as returning components directly, can you point me to the right direction and i'll take a look and try to implement it. this is a fairly important feature for my project...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 12:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
uggh SelectParser and QueryTranslator are the offending classes - both are starting to look pretty ugly now, so don't expect this code to be as readable as other Hibernate code


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