-->
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.  [ 5 posts ] 
Author Message
 Post subject: Setting criteria on subclass but returning superclass - HQL
PostPosted: Thu Dec 22, 2005 4:58 am 
Newbie

Joined: Thu Dec 22, 2005 4:50 am
Posts: 10
I have 3 objects, that are like this

Entity
Business : Entity
Individual : Entity

Business and Individual are inherited from Entity
I want a return type of Entity (Which will be a mix of Business and Individuals).
I can't seem to set criteria on the subclasses (Business or Entity) in HQL.

Is it possible?

I tried something like this :

select entity from Entity entity, Individual i, Business b
where i.FirstName like ......

but returned way too many results and was extrememly slow.

I should add that an entity can ONLY be a Business or Individual
and if primary key of Business is 56 then the primary key of entity is also 56
Any suggestions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 6:16 pm 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
what strategy for mapping the inheritance do you use?
usually "from ent Entity where ...." should return also derived objects (if your inheritance mapping strategy supports that)

Cheers,
Radu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 9:21 pm 
Newbie

Joined: Thu Dec 22, 2005 4:50 am
Posts: 10
Yes, I can do a search with no criteria and get back Entities (which are actually of type Individual and Business). I can set criteria on the Entity but it can only relate to the entity class (which works as expected), but is not what i want. Basically it all works great without criteria.

Problem is i need to set criteria on the Individual object but return Entity objects.

At the moment it looks like i have to resort to running two queries, one to return Individuals (setting the criteria), and one query to run the Businesses (also setting criteria)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 11:51 pm 
Newbie

Joined: Thu Dec 22, 2005 4:50 am
Posts: 10
This seems to be a big problem for me.
How does HQL support inheritence and criteria on the subclass.

The entity can be a business or a individual

Entity
Business : Entity
Individual : Entity

The Entity plays one or many roles, one being a Client ( a bag)

Client inherits from Role
(Client : Role)

The client then has applications from there. (bag)

Say I took my original problem and decided to return Businesses instead of Entities. I can set criteria ok on the Businesses however i need to be able to search all Clients that match this role that the entity is playing, and then search the associated applications.




Ive done a lot of reading, and searching, to no prevail. (equivalient of Hibernate 2.1 i believe).


It is a comples scenario but posts like this from Gavin on the HIBERNATE forum do not sound promising : (referring to 2.1)

"HQL never, ever supported navigating through a collection-valued association! I find it very difficult to believe that this ever worked, but if it did, it worked by accident in some small number of cases and was never part of the official definition of HQL as per the documentation."


can someone confirm if what i am attempting can be done please??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 23, 2005 5:42 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
Well, I'm using polymorphic collections myself and they are working.
Post details of your mappings, class definitions and queries you want to perform.

cheers,
radu


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